-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
51 lines (41 loc) · 1.03 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
package toxy
import (
"log"
"os"
"github.com/BurntSushi/toml"
)
const (
Random string = "random"
Sequential = "sequential"
)
const (
ServiceUp string = "up"
ServiceDown string = "down"
ServiceUnknown string = "unknown"
)
type ServerConfig struct {
Port int `toml:"port"`
Hostname string `toml:"hostname"`
Name string `toml:"name"`
}
type Config struct {
Port int `toml:"port"`
Hostname string `toml:"hostname"`
CertPath string `toml:"cert_file"`
KeyPath string `toml:"key_file"`
LoadBalancer string `toml:"load_balancer"`
ResolveInterval int `toml:"resolve_interval"`
Server map[string][]ServerConfig
}
func LoadConfig() Config {
content, err := os.ReadFile("./config.toml")
if err != nil {
log.Fatalf("Failed to load server config \n %v", err)
}
defaultConfStruct := Config{}
_, err = toml.Decode(string(content), &defaultConfStruct)
if err != nil {
log.Fatalf("Failed to parse server config \n %v", err)
}
return defaultConfStruct
}