-
Notifications
You must be signed in to change notification settings - Fork 5
/
config.go
61 lines (53 loc) · 1.33 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
package gtm
import (
"encoding/json"
"io"
"io/ioutil"
)
type HealthCheck interface {
Start()
Receive() []IP
}
type Config struct {
Domains []*Domain `json:"domains"`
Port int `json:"port"`
RelayServer string `json:"relay_server"`
}
type Record struct {
Name string `json:"name"`
IPs []IP `json:"ips"`
TTL int `json:"ttl"`
HealthCheckConfig HealthCheckConfig `json:"health_check"`
HealthCheck HealthCheck
}
type Domain struct {
DomainName string `json:"name"`
Records []*Record `json:"records"`
}
//HealthCheckConfig Config for health check
type HealthCheckConfig struct {
Type string `json:"type"`
PORT int `json:"port"`
HTTPS bool `json:"https"`
SkipSSL bool `json:"skip_ssl"`
PATH string `json:"path"`
HTTPStatusCode int `json:"http_status_code"`
Fequency string `json:"frequency"`
}
type IP struct {
Address string `json:"address"`
Host string `json:"layer7_health_check_host"`
}
func ParseConfig(reader io.Reader) (*Config, error) {
bytes, err := ioutil.ReadAll(reader)
if err != nil {
return nil, err
}
s := []byte(bytes)
var config Config
err = json.Unmarshal([]byte(s), &config)
if err != nil {
return nil, err
}
return &config, err
}