-
Notifications
You must be signed in to change notification settings - Fork 5
/
config.go
57 lines (48 loc) · 1.12 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
package cachecluster
import (
"gopkg.in/ini.v1"
)
type (
// CacheConfig hold settings for the groupcache service
CacheConfig struct {
Port int
GCPercent int `ini:"gc_percent"`
PeriodicRelease int
}
// ClusterConfig hold settings for the cluster service
ClusterConfig struct {
Port int
Heartbeat int
}
// MatchConfig hold settings for instance matching
MatchConfig struct {
Project string
Zone string
NetworkInterface string
Tags []string
Meta map[string]string `ini:"meta"`
}
// Config holds configuration settings
Config struct {
Cache CacheConfig
Cluster ClusterConfig
Match MatchConfig
}
)
// LoadConfig loads cachecluster Config from an .ini file
// default filename is "cachecluster.ini"
func LoadConfig(filename string) (*Config, error) {
if filename == "" {
filename = "cachecluster.ini"
}
cfg, err := ini.Load(filename)
if err != nil {
return nil, err
}
cfg.BlockMode = false
cfg.NameMapper = ini.TitleUnderscore
var c Config
cfg.MapTo(&c)
c.Match.Meta = cfg.Section("meta").KeysHash()
return &c, nil
}