-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
57 lines (46 loc) · 1.44 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
package main
import (
"log"
"os"
"github.com/go-playground/validator/v10"
"gopkg.in/yaml.v3"
)
type Config struct {
IntervalSeconds int `yaml:"intervalSeconds" validate:"required"`
TeamSpeak TeamSpeak `yaml:"teamSpeak"`
Telegram Telegram `yaml:"telegram"`
}
type TeamSpeak struct {
FavoriteUsers []string `yaml:"favoriteUsers"`
Address string `yaml:"address" validate:"required"`
Username string `yaml:"username" validate:"required"`
Password string `yaml:"password" validate:"required"`
VirtualServerId string `yaml:"virtualServerId" validate:"required"`
}
type Telegram struct {
BotToken string `yaml:"botToken" validate:"required"`
ChatId int64 `yaml:"chatId" validate:"required"`
MessageId int `yaml:"messageId"`
Separator string `yaml:"separator" validate:"required"`
ZeroUsers string `yaml:"zeroUsers" validate:"required"`
UpdateTitle bool `yaml:"updateTitle"`
}
// loadConfig reads the config file
func loadConfig(configPath string) Config {
file, err := os.ReadFile(configPath)
if err != nil {
log.Fatal(err)
}
var config Config
if err := yaml.Unmarshal(file, &config); err != nil {
log.Fatal(err)
}
return config
}
func (config *Config) validate() {
validate := validator.New()
if err := validate.Struct(config); err != nil {
validationErrors := err.(validator.ValidationErrors)
log.Fatalf("missing values in config\n%s", validationErrors)
}
}