-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
62 lines (52 loc) · 1.48 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
package main
import (
"os"
"time"
"gopkg.in/yaml.v2"
)
const defaultListenAddr = ":9999"
const defaultTorAddr = "localhost:9050"
const defaultTimeout = time.Second * 10
const defaultCheckInterval = time.Second * 30
const defaultLogLevel = "error"
const defaultLogFormat = "fmt"
const targetTypeHTTP = "http"
const targetTypeTCP = "tcp"
type Config struct {
ListenAddr string `yaml:"listen_addr,omitempty"`
TorAddr string `yaml:"tor_addr,omitempty"`
Timeout time.Duration `yaml:"timeout,omitempty"`
CheckInterval time.Duration `yaml:"check_interval,omitempty"`
LogLevel string `yaml:"log_level"`
LogFormat string `yaml:"log_format"`
Targets []Target `yaml:"targets,omitempty"`
InsecureSkipVerify bool `yaml:"insecure_skip_ssl_verify"`
}
type Target struct {
Name string `yaml:"name"`
Type string `yaml:"type"`
URL string `yaml:"url"`
}
func NewConfig() *Config {
return &Config{
ListenAddr: defaultListenAddr,
TorAddr: defaultTorAddr,
Timeout: defaultTimeout,
CheckInterval: defaultCheckInterval,
LogLevel: defaultLogLevel,
LogFormat: defaultLogFormat,
InsecureSkipVerify: false,
}
}
func LoadConfig(path *string) (error, *Config) {
cfg := NewConfig()
bytes, err := os.ReadFile(*path)
if err != nil {
return err, cfg
}
err = yaml.Unmarshal(bytes, &cfg)
if err != nil {
return err, cfg
}
return nil, cfg
}