-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
54 lines (47 loc) · 1.46 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
package main
import (
"errors"
"io/ioutil"
"net/url"
"strings"
"github.com/chennqqi/goutils/utime"
)
type VZone struct {
MatchClients []string `json:"match_clients" yaml:"match_clients"`
File string `json:"file" yaml:"file"`
Checker string `json:"checker" yaml:"checker"`
}
type ServerConf struct {
Name string `json:"name" yaml:"name"`
VZones []VZone `json:"v_zones" yaml:"v_zones"`
RoundRobin bool `json:"round_robin" yaml:"round_robin"`
}
type UpstreamConf struct {
Name string `json:"name" yaml:"name"`
CacheExpire utime.Duration `json:"cache_expire" yaml:"cache_expire"`
Upstreams []string `json:"upstreams" yaml:"upstreams"`
}
type Config struct {
Servers []ServerConf `json:"servers" yaml:"servers"`
Forwards []UpstreamConf `json:"forwards" yaml:"forwards"`
LogFile string `json:"log_file" yaml:"log_file"`
LogLevel string `json:"log_level" yaml:"log_level"`
Addr string `json:"addr" yaml:"addr" default:""`
HealthHost string `json:"health" yaml:"health"`
}
func ReadTxt(file string) ([]byte, error) {
if strings.HasPrefix(file, "consul://") {
u, err := url.Parse(file)
if gconsul == nil {
return nil, errors.New("consul not set")
} else if err != nil {
return nil, err
} else if u.Path != "" {
return gconsul.Get(u.Path[1:])
} else {
return nil, errors.New("consul path is nil")
}
} else {
return ioutil.ReadFile(file)
}
}