-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmain.go
73 lines (63 loc) · 1.39 KB
/
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"fmt"
"github.com/sherifabdlnaby/configuro"
)
//Config Is our main Application Config Struct.
type Config struct {
// Primitive Types
Number int
NumberList []int `config:"number_list"`
Word string
AnotherWord string `config:"another_word"`
WordMap map[string]string `config:"word_map"`
// Nested Objects (Ptr and None)
Database *Database
Logger Logger
}
//Database A sub-config struct
type Database struct {
Hosts []string
Username string
Password string
}
//Logger Another sub-config struct
type Logger struct {
Level string
Debug bool
}
func main() {
// Create Configuro Object
Loader, err := configuro.NewConfig(
configuro.WithLoadFromConfigFile("./config.yml", false))
if err != nil {
panic(err)
}
// Create our Config holding Struct
config := &Config{Word: "default value in struct."}
// Load Our Config.
err = Loader.Load(config)
if err != nil {
panic(err)
}
// Print Result.
fmt.Printf(`
Config Struct:
Number: %d
NumberList: %v
--------------
Word: %s
AnotherWord: %s
WordMap: %v
--------------
Database:
Hosts: %v
Username: %s
Password: %s
--------------
Logger:
Level: %s
Debug: %t
`, config.Number, config.NumberList, config.Word, config.AnotherWord, config.WordMap, config.Database.Hosts,
config.Database.Username, config.Database.Password, config.Logger.Level, config.Logger.Debug)
}