-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
36 lines (30 loc) · 812 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
package main
import (
"encoding/json"
"fmt"
"log"
"github.com/NathanBak/cfgbuild/examples/bootstrap/config"
)
// This main function uses a config that bootstraps itself to initialize the fields.
//
// Expected output:
//
// {"myInt":8081,"myFloat":3.14159,"myString":"Smoke me a kipper, I'll be back for breakfast!","myBool":false}
// cfg.MyInt = 8081
// cfg.MyFloat = 3.14159
// cfg.MyString = Smoke me a kipper, I'll be back for breakfast!
func main() {
cfg, err := config.New()
if err != nil {
log.Fatal(err)
}
// print cfg as JSON string
buf, err := json.Marshal(cfg)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(buf))
// print out the different values in the config
fmt.Printf("cfg.MyInt = %v\ncfg.MyFloat = %v\ncfg.MyString = %v\n",
cfg.MyInt, cfg.MyFloat, cfg.MyString)
}