/
config.go
57 lines (47 loc) · 922 Bytes
/
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
package occult
import (
"io/ioutil"
"github.com/golang/glog"
"launchpad.net/goyaml"
)
/*
Configuration file. Example:
app:
name: "myapp"
cache_cap: 1000
cluster:
nodes:
- id: 0
- addr: ":33330"
- id: 1
- addr: ":33331"
*/
type Config struct {
App *App `yaml:"app"`
Cluster *Cluster `yaml:"cluster"`
}
// Read the occult configuration file.
func ReadConfig(filename string) (config *Config, err error) {
var data []byte
data, err = ioutil.ReadFile(filename)
if err != nil {
return
}
config = &Config{}
err = goyaml.Unmarshal(data, config)
if err != nil {
return
}
glog.V(1).Infof("config:\n%s\n\n", config)
return
}
func OneNodeConfig() (config *Config) {
return &Config{App: &App{Name: "eval", CacheCap: 1000}}
}
func (c *Config) String() string {
d, err := goyaml.Marshal(c)
if err != nil {
glog.Fatal(err)
}
return string(d)
}