-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetting.go
34 lines (29 loc) · 867 Bytes
/
setting.go
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
package config
import (
"reflect"
"sort"
)
/*
Setting represents one configuration value.
It represents a value parsed from either a struct field or passed to Config.Var.
*/
type Setting struct {
// Path is the given path within the configuration hierarchy. This should
// be used by Loader implementations to create or identify the parameter.
// it will never be nil when passed to Loader.Init().
Path *Path
// Tag is the struct tag parsed by Config.Scan or passed to Config.Var.
Tag reflect.StructTag
// Setter is an implementation of Setter. When passed to Loader.Init(), it
// will never be nil.
Setter
}
type settings []Setting
func (s *settings) add(setting Setting) {
i := sort.Search(len(*s), func(i int) bool {
return PathCmp(setting.Path, (*s)[i].Path) < 0
})
*s = append(*s, Setting{})
copy((*s)[i+1:], (*s)[i:])
(*s)[i] = setting
}