-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig.go
63 lines (55 loc) · 1.2 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
package main
import (
flag "github.com/ogier/pflag"
"gopkg.in/yaml.v2"
"io/ioutil"
"path/filepath"
)
type Config struct {
Backend_timeout int
MaxKeepAliveConnections int
Aerospike struct {
WriteTimeout int
ReadTimeout int
ConnectionTimeout int
ConnectionQueueSize int
Hosts []struct {
Host string
Port int
}
}
Http struct {
Port string
}
Memcache struct {
Port string
}
}
var config *Config
var config_filename string
var log_level string
func LoadConfigFromString(yaml_config []byte) *Config {
var err error
var config *Config
if err = yaml.Unmarshal(yaml_config, &config); err != nil {
panic(err)
}
return config
}
func LoadConfigFromFileName(config_filename string) *Config {
var err error
var yaml_config []byte
filename, _ := filepath.Abs(config_filename)
if yaml_config, err = ioutil.ReadFile(filename); err != nil {
panic(err)
}
return LoadConfigFromString(yaml_config)
}
func ReadConfig() {
config = LoadConfigFromFileName(config_filename)
}
func init() {
flag.StringVar(&config_filename, "config", "config.yaml", "Config file")
flag.StringVar(&log_level, "log-level", "INFO", "log level")
flag.Parse()
}