/
config.go
79 lines (69 loc) · 1.69 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
package main
import (
"io/ioutil"
"os"
"time"
"github.com/BurntSushi/toml"
)
func parseConifg(filename string) (*Config, error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
}
defer f.Close()
buf, err := ioutil.ReadAll(f)
if err != nil {
return nil, err
}
var config Config
err = toml.Unmarshal(buf, &config)
return &config, err
}
// Config holds the beco's config
type Config struct {
Port int `toml:"port"`
Addr string `toml:"addr"`
Proxys []Proxy `toml:"proxys"`
SSL SSL `toml:"ssl"`
Auth Auth `toml:"auth"`
}
// Proxy holds the config for backend host
type Proxy struct {
Prefix string `toml:"prefix"`
Auth Auth `toml:"auth"`
Backends []Backend `toml:"backends"`
SetHeaders []Header `toml:"setheaders"`
}
// SSL holds the SSL configuration
type SSL struct {
Addr string `toml:"addr"`
Port int `toml:"port"`
Cert string `toml:"cert"`
Key string `toml:"key"`
}
// Header is the http Header. Key:Value
type Header struct {
Key string `toml:"key"`
Value string `toml:"value"`
}
// Backend is the proxy host
type Backend struct {
//support local static files with the prefix static:
Host string `toml:"host"`
Weight int `toml:"weight"`
MaxFails int `toml:"max_fails"`
FailTimeout time.Duration `toml:"fail_timeout"`
Backup bool `toml:"backup"`
HealthCheck HealthCheck `toml:"health_check"`
}
// HealthCheck to Match the response
type HealthCheck struct {
Status int `toml:"status"`
Body string `toml:"body"`
Herders []Header `toml:"headers"`
}
// Auth provider
type Auth struct {
Provider string `toml:"provider"`
Config string `toml:"config"`
}