-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
35 lines (30 loc) · 857 Bytes
/
types.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
35
package ecp
import (
"os"
"reflect"
"strings"
)
type (
// BuildKeyFunc how to get the key name
BuildKeyFunc func(structure, field string, tag reflect.StructTag) string
// LookupValueFunc returns the value and whether exist
LookupValueFunc func(key string) (value string, exist bool)
// SetValueFunc set the field value and returns whether this filed is set by this function
SetValueFunc func(tag reflect.StructTag, field reflect.Value, val string) bool
)
const space = " "
// default functions
var (
buildKeyFromEnv = func(structure, field string, tag reflect.StructTag) (key string) {
if e := tag.Get("env"); e != "" {
return e
}
if structure == "" {
key = field
} else {
key = structure + "_" + field
}
return strings.ToUpper(key)
}
lookupValueFromEnv = func(key string) (string, bool) { return os.LookupEnv(key) }
)