-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
75 lines (68 loc) · 2.1 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
74
75
package psmconfig
import (
"flag"
"io/ioutil"
"log"
yaml "gopkg.in/yaml.v2"
)
// Config Global Variable
// Store Configuration Options
var Config *Conf
// Conf Struct
type Conf struct {
Name string `yaml:"name,omitempty"`
Env string `yaml:"env,omitempty"`
Host string `yaml:"host,omitempty"`
Port int `yaml:"port,omitempty"`
Static string `yaml:"static,omitempty"`
Mongo struct {
Host string `yaml:"host,omitempty"`
Port int `yaml:"port,omitempty"`
User string `yaml:"user,omitempty"`
Pass string `yaml:"pass,omitempty"`
Path string `yaml:"path,omitempty"`
} `yaml:"mongo,omitempty"`
CouchBase struct {
Host string `yaml:"host,omitempty"`
Port int `yaml:"port,omitempty"`
User string `yaml:"user,omitempty"`
Pass string `yaml:"pass,omitempty"`
Path string `yaml:"path,omitempty"`
} `yaml:"couchbase,omitempty"`
ES struct {
Host string `yaml:"host,omitempty"`
Port int `yaml:"port,omitempty"`
User string `yaml:"user,omitempty"`
Pass string `yaml:"pass,omitempty"`
Path string `yaml:"path,omitempty"`
} `yaml:"es,omitempty"`
Redis struct {
Host string `yaml:"host,omitempty"`
Port int `yaml:"port,omitempty"`
User string `yaml:"user,omitempty"`
Pass string `yaml:"pass,omitempty"`
Path string `yaml:"path,omitempty"`
} `yaml:"redis,omitempty"`
Twitter struct {
ConsumerKey string `yaml:"consumer-key,omitempty"`
ConsumerSecret string `yaml:"consumer-secret,omitempty"`
AccessToken string `yaml:"access-token,omitempty"`
AccessTokenSecret string `yaml:"access-token-secret,omitempty"`
} `yaml:"twitter,omitempty"`
Log struct{} `yaml:"log,omitempty"`
Proto struct{} `yaml:"proto,omitempty"`
API map[string]string `yaml:"api,omitempty"`
}
// NewConfig Init
func NewConfig() {
var path string
flag.StringVar(&path, "config", "conf/default.yaml", "Parse Configuration File")
flag.Parse()
data, err := ioutil.ReadFile(path)
if err != nil {
log.Printf("[PSM-CONFIG] Configuration parsing error: %v", err)
panic(err)
}
yaml.Unmarshal(data, &Config)
log.Printf("[PSM-CONFIG] Configuration loaded: %v", Config)
}