forked from mkock/configurama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_prefix_test.go
62 lines (55 loc) · 1.67 KB
/
example_prefix_test.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
package configurama_test
import (
"fmt"
"github.com/mkock/configurama"
)
// Example_Prefix provides a usage example for package configurama using
// the "prefix" parameter to match configuration parameters where their
// names are grouped together using a common prefix.
func Example_Prefix() {
config := configurama.New(map[string]map[string]string{
"Database": {
"db.master.type": "mysql",
"db.master.Host": "192.168.0.1",
"db.master.Port": "3306",
"db.master.User": "master-admin",
"db.master.Password": "master-secret",
"db.slave.type": "mysql",
"db.slave.Host": "192.168.0.2",
"db.slave.Port": "3306",
"db.slave.User": "slave-admin",
"db.slave.Password": "slave-secret",
},
})
type dbConfig struct {
Type, Host, Port, User, Password string
}
var masterDBConf, slaveDBConf dbConfig
config.Extract("Database", "db.master.", &masterDBConf)
config.Extract("Database", "db.slave.", &slaveDBConf)
fmt.Println("Master")
fmt.Println("Type: " + masterDBConf.Type)
fmt.Println("Host: " + masterDBConf.Host)
fmt.Println("Port: " + masterDBConf.Port)
fmt.Println("User: " + masterDBConf.User)
fmt.Println("Password: " + masterDBConf.Password)
fmt.Println("Slave")
fmt.Println("Type: " + slaveDBConf.Type)
fmt.Println("Host: " + slaveDBConf.Host)
fmt.Println("Port: " + slaveDBConf.Port)
fmt.Println("User: " + slaveDBConf.User)
fmt.Println("Password: " + slaveDBConf.Password)
// Output:
// Master
// Type: mysql
// Host: 192.168.0.1
// Port: 3306
// User: master-admin
// Password: master-secret
// Slave
// Type: mysql
// Host: 192.168.0.2
// Port: 3306
// User: slave-admin
// Password: slave-secret
}