-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
87 lines (71 loc) · 1.57 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package config
/**
*@Author icepan
*@Date 7/22/21 09:32
*@Describe
**/
import (
"fmt"
"github.com/spf13/viper"
)
var Conf EagleConfig
type EagleConfig struct {
Labels []string `yaml:"labels"`
*HealthCheckConfig `mapstructure:"health"`
*EtcdConfig `mapstructure:"etcd"`
*ServerConfig `mapstructure:"server"`
*DockerConfig `mapstructure:"docker"`
}
type CheckerConfig struct {
Type string `yaml:"type"`
URL string `yaml:"url"`
}
type HealthCheckConfig struct {
Timeout uint8 `yaml:"timeout"`
Interval uint8 `yaml:"interval"`
*CheckerConfig `mapstructure:"checker"`
}
type EtcdConfig struct {
Endpoints []string `yaml:"endpoints"`
Prefix string `yaml:"prefix"`
}
type ServerConfig struct {
Host string `yaml:"host"`
Port string `yaml:"port"`
}
type DockerConfig struct {
Network string `yaml:"network"`
}
func InitConfigDefault() {
sc := &ServerConfig{
Host: "127.0.0.1",
Port: "9999",
}
Conf.ServerConfig = sc
ec := &EtcdConfig{
Endpoints: []string{fmt.Sprintf("%s:%s", "127.0.0.1", "2380")},
Prefix: "eagle",
}
Conf.EtcdConfig = ec
health := &HealthCheckConfig{
Timeout: 5,
Interval: 2,
CheckerConfig: &CheckerConfig{
Type: "tcp",
},
}
Conf.HealthCheckConfig = health
docker := &DockerConfig{Network: "bridge"}
Conf.DockerConfig = docker
Conf.Labels = []string{"eagle"}
}
func InitConfigFromFile(filepath string) error {
viper.SetConfigFile(filepath)
if err := viper.ReadInConfig(); err != nil {
return err
}
if err := viper.Unmarshal(&Conf); err != nil {
return err
}
return nil
}