-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
39 lines (35 loc) · 887 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
package main
import (
"fmt"
"log"
"github.com/antonmashko/envconf"
"github.com/antonmashko/envconf/external"
"github.com/antonmashko/envconf/external/json"
"github.com/antonmashko/envconf/option"
)
type Example struct {
Field1 string `flag:"flag-name" env:"ENV_VAR_NAME" default:"default-value"`
Field2 string `json:"field-2"`
Inner struct {
FlagField string `flag:"*"`
EnvVarField string `env:"*"`
}
Password string `default:"pass1"`
API struct {
Token string `default:"token1"`
}
}
// Run `go run main.go --help` for getting help output with auto-generated names
func main() {
var cfg Example
err := envconf.Parse(&cfg,
option.WithLog(log.Default()),
option.WithFlagConfigFile("config", "./conf.json", "", func(b []byte) (external.External, error) {
return json.Json(b), nil
}),
)
if err != nil {
panic(err)
}
fmt.Printf("%#v\n", cfg)
}