-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
48 lines (40 loc) · 839 Bytes
/
config.go
File metadata and controls
48 lines (40 loc) · 839 Bytes
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
package main
import (
"github.com/knadh/koanf"
"github.com/knadh/koanf/parsers/json"
"github.com/knadh/koanf/providers/file"
"github.com/mitchellh/go-homedir"
"log"
)
var k = koanf.New(".")
func loadConfig() bool {
home, err := homedir.Dir()
if err != nil {
log.Fatal(err.Error())
return false
}
if err := k.Load(file.Provider(home + "/.ehmgr.json"), json.Parser()); err != nil {
log.Fatalf("Failed to load config: %s", err)
return false
}
ok, errs := checkKeySet([]string{
"endpoint",
"key",
"ip",
"domain",
"package",
})
if !ok {
log.Fatalf("Invalid configuration, keys not found: %v", errs)
}
return true
}
func checkKeySet(keys []string) (bool, []string) {
var errs []string
for _, key := range keys {
if !k.Exists(key) {
errs = append(errs, key)
}
}
return len(errs) == 0, errs
}