github.com/whiteboxio/flow@v0.0.3-0.20190918184116-508d75d68a2c/pkg/types/common.go (about) 1 package types 2 3 import ( 4 "reflect" 5 "strings" 6 ) 7 8 const ( 9 // KeySepCh is a char used as a key fragment separator. A dot by default. 10 KeySepCh = "." 11 ) 12 13 // Key type represents a key used in key-value relationships. A key is a 14 // composite structure: itconsists of fragments. Say, a key `foo.bar.baz` 15 // consists of 3 fragments: []string{"foo", "bar", "baz"} (split by `KeySepCh`). 16 type Key []string 17 18 // String satisfies Stringer interface 19 func (key Key) String() string { 20 return strings.Join(key, KeySepCh) 21 } 22 23 func (key Key) Equals(k2 Key) bool { 24 return reflect.DeepEqual(key, k2) 25 } 26 27 // NewKey is a default constructor used for a new key instantiation. 28 // Automatically splits the input string into key fragments. 29 func NewKey(str string) Key { 30 if len(str) == 0 { 31 return Key(nil) 32 } 33 return Key(strings.Split(str, KeySepCh)) 34 } 35 36 // Value represents a value in key-value relationships. 37 type Value interface{} 38 39 // KeyValue represents a basic key-value pair. It's a composite data structure. 40 type KeyValue struct { 41 Key Key 42 Value Value 43 } 44 45 // Params is a simple string-Value map, used to pass flattened parameters. 46 type Params map[string]Value