-
Notifications
You must be signed in to change notification settings - Fork 0
/
kuttilib-config.go
52 lines (40 loc) · 1017 Bytes
/
kuttilib-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
package kuttilib
import (
"encoding/json"
"github.com/kuttiproject/workspace"
)
const configFileName = "kuttilib-clusters.json"
var (
clusterconfigmanager workspace.ConfigManager
config *clusterConfigData
)
type clusterConfigData struct {
Clusters map[string]*Cluster
}
func (cc *clusterConfigData) Serialize() ([]byte, error) {
return json.Marshal(cc)
}
func (cc *clusterConfigData) Deserialize(data []byte) error {
var loadedconfig *clusterConfigData
err := json.Unmarshal(data, &loadedconfig)
if err == nil {
cc.Clusters = loadedconfig.Clusters
}
return err
}
func (cc *clusterConfigData) SetDefaults() {
cc.Clusters = map[string]*Cluster{}
}
func setworkspaceconfigmanager() {
config = &clusterConfigData{
Clusters: map[string]*Cluster{},
}
var err error
clusterconfigmanager, err = workspace.NewFileConfigManager(configFileName, config)
if err != nil {
panic("could not initialize cluster configuration manager")
}
}
func init() {
setworkspaceconfigmanager()
}