-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
66 lines (55 loc) · 1.34 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
package main
import (
"os"
"time"
"gopkg.in/yaml.v3"
)
type config struct {
Addr string `yaml:"addr"`
Endpoints map[string]endpointConfig `yaml:"endpoints"`
}
type endpointConfig struct {
Path string `yaml:"path"`
Target string `yaml:"target"`
KubernetesTarget *kubeTarget `yaml:"kubernetes_target"`
RefreshInterval time.Duration `yaml:"refresh_interval"`
Auth endpointAuth `yaml:"auth"`
InsecureSkipVerify bool `yaml:"insecure_skip_verify"`
}
type kubeTarget struct {
Endpoint kubeEndpointTarget `yaml:"endpoint"`
}
type kubeEndpointTarget struct {
Name string `yaml:"name"`
Namespace string `yaml:"namespace"`
Port int `yaml:"port"`
Path string `yaml:"path"`
Scheme string `yaml:"scheme"`
}
type endpointAuth struct {
Type authType `yaml:"type"`
Token string `yaml:"token"`
}
type authType string
var (
authModeNone authType = ""
authModeBearer authType = "Bearer"
authModeKube authType = "Kubernetes"
)
func readConfig(path string) (config, error) {
conf := config{
Addr: ":80",
}
if path == "" {
return conf, nil
}
configFile, err := os.ReadFile(path)
if err != nil {
return config{}, err
}
err = yaml.Unmarshal(configFile, &conf)
if err != nil {
return config{}, err
}
return conf, nil
}