-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc.go
More file actions
80 lines (80 loc) · 2.61 KB
/
doc.go
File metadata and controls
80 lines (80 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//Package config provides types that allow loading, storing, retrieving, and
//removing arbitrary values that are referenced by keys.
//
//The Config Type
//
//We can create instances of Config with New().
//The zero valued &Config{} is not in a valid state and will likely cause panics
//if used.
//The New() func automatically sets Config's KeyParser to PeriodSeparatorKeyParser.
//This means that all string key parameters to Config methods will be converted
//to Key types in the manner of "a.b.c.d" -> Key([]string{"a", "b", "c", "d"}).
//A Config's KeyParser field can be changed before use to override this functionality.
//
//Inserting values into a Config is simple and type agnostic.
//The Put*() methods all return whether or not the internal set of values changed.
//
// c := New()
// c.Put("foo", "bar") //true
// c.Put("foo", "bar") //false
// c.Put("foo", 1024) //true
//
//We can additionally use the Loader type to insert multiple values at once
//and from varying sources instead of calling individual Put*() methods.
//
// type sliceLoader []interface{}
//
// func (sl sliceLoader) Load() (*Values, error) {
// values := NewValues()
// for i, v := range sl {
// key := NewKey("slice", fmt.Sprint(i))
// values.Put(key, v)
// }
// return values, nil
// }
//
// loader := sliceLoader([]interface{}{"hello", "world", 234, true})
// c := New()
// c.MergeLoaders(loader) //true, nil
//
// c.Get("slice.0") //hello
// c.Get("slice.1") //world
// c.Get("slice.2") //234
// c.Get("slice.3") //true
//
//See the Loader documentation and the loader subdirectory for information
//about pre-written loaders for common use cases.
//
//The Values and Key Types
//
//Type Values provides the actaul storage and retrieval of interface{} values.
//The values stored in a Values type are referenced by the Key type.
//Values is implemented as a tree with possible multiple children at each node.
//Each individual string in a Key is the "pointer" to the subtree of possibly
//more values.
//
//For example:
//
// //the following code...
//
// v := NewValues()
// v.Put(NewKey("a", "b"), 1)
// v.Put(NewKey("a", "c"), 2)
// v.Put(NewKey("d"), 3)
//
// //results in this structure.
// // __root__
// // | |
// // a d
// // | |
// // b--+--c 3
// // | |
// // 1 2
//
//Continuing from this example, if we were to call v.Put(NewKey("a"), true),
//that would completely remove the [a b] -> 1 and [a c] -> 2 associations from v.
//
//If we were to call v.Put(NewKey("a", "e"), "foobar"), that would result in the
//[a b] and [a c] associations remaining and the new [a e] -> "foobar" within v.
//
package config