-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (51 loc) · 1002 Bytes
/
main.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
configer "github.com/wzshiming/configer"
ffmt "gopkg.in/ffmt.v1"
)
func main() {
examples1()
}
type BB struct {
Hello string `configer:"world"` // Take the default value "world"
Shell string `configer:",env" env:"SHELL"` // Take the value of env
EnvNone string `configer:",env" env:"NONE"` // An empty env
}
type TT struct {
LoadFilePath string `configer:"./examples1.json,env"` // Loaded file path
BB BB `configer:",load" load:"LoadFilePath"` // Load path field
}
func examples1() {
b := BB{}
configer.Load(&b)
ffmt.Puts(b)
/*
{
Hello: "world"
Shell: "/bin/bash"
EnvNone: ""
}
*/
configer.Load(&b, "./examples1.json")
ffmt.Puts(b)
/*
{
Hello: "json"
Shell: "/bin/bash"
EnvNone: "env none"
}
*/
t := TT{}
configer.Load(&t)
ffmt.Puts(t)
/*
{
LoadFilePath: "./examples1.json"
BB: {
Hello: "json"
Shell: "/bin/bash"
EnvNone: "env none"
}
}
*/
}