-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.go
More file actions
39 lines (36 loc) · 951 Bytes
/
config.go
File metadata and controls
39 lines (36 loc) · 951 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
package main
import (
"github.com/spf13/viper"
"log"
"os"
"time"
)
type config struct {
KeepAlivePeriod time.Duration
ConnectTimeout time.Duration
Auths map[string]string
AsCluster map[string]string
}
func getConfig(v *viper.Viper, configFile string) *config {
if _, err := os.Stat(configFile); os.IsNotExist(err) {
log.Printf("Get config failed: %s", err)
os.Exit(1)
}
v.SetConfigFile(configFile)
v.SetConfigType("yaml")
err := v.ReadInConfig()
if err != nil {
log.Printf("Get config failed: %s", err)
os.Exit(1)
}
connectTimeout := v.GetInt("connect_timeout")
keepAlivePeriod := v.GetInt("keepalive_period")
auths := v.GetStringMapString("auths")
asCluster := v.GetStringMapString("as_cluster")
return &config{
KeepAlivePeriod: time.Duration(keepAlivePeriod) * time.Second,
ConnectTimeout: time.Duration(connectTimeout) * time.Second,
Auths: auths,
AsCluster: asCluster,
}
}