-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
77 lines (59 loc) · 1.46 KB
/
config.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
74
75
76
77
////////////////////////////////////////////////////////////////////////////
// Porgram: config - Config handling
// Authors: Antonio Sun (c) 2015, All rights reserved
////////////////////////////////////////////////////////////////////////////
package main
import (
"io/ioutil"
"strings"
)
import (
"gopkg.in/yaml.v2"
)
////////////////////////////////////////////////////////////////////////////
// Constant and data type/structure definitions
/*
dbuser: uu
dbpassword: "pp"
pod:
- id: v746b
instance:
- database: perfwhit746
dbserver: TorsvPerfDb07
servers: TorsvPerfBje05 TorsvPerfBje06 TorsvPerfApp03 TorsvPerfApp06
- database: perfwhit746b
dbserver: TorsvPerfDb07
servers: TorsvPerfBje05 TorsvPerfBje06 TorsvPerfApp03 TorsvPerfApp06
*/
type instance struct {
Database string
Dbserver string
Servers string
}
type pod struct {
Id string
Instance []instance
}
var config struct {
DbUser string
DbPassword string
Pod []pod
}
////////////////////////////////////////////////////////////////////////////
// Function definitions
func configGet(args0 string) {
if len(options.ConfigFile) == 0 {
options.ConfigFile = Basename(args0) + options.ConfigExt
}
cfgStr, err := ioutil.ReadFile(options.ConfigFile)
err = yaml.Unmarshal(cfgStr, &config)
check(err)
//fmt.Printf("] %#v\r\n", config)
}
func Basename(s string) string {
n := strings.LastIndexByte(s, '.')
if n > 0 {
return s[:n]
}
return s
}