63 lines
1.2 KiB
Go
63 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
type TlsConfig struct {
|
|
Enable bool `yaml:"enable"`
|
|
CertFile string `yaml:"certificate"`
|
|
CertKeyFile string `yaml:"certificate_key"`
|
|
}
|
|
|
|
type ServerAuthConfig struct {
|
|
Username string `yaml:"username"`
|
|
Password string `yaml:"password"`
|
|
}
|
|
|
|
type ServerConfig struct {
|
|
Listen string `yaml:"listen"`
|
|
Auth ServerAuthConfig `yaml:"auth"`
|
|
Tls TlsConfig `yaml:tls`
|
|
}
|
|
|
|
type RemoteItemConfigItem struct {
|
|
Label string `yaml:"label"`
|
|
Message string `yaml:"message"`
|
|
}
|
|
|
|
type RemoteItemConfig struct {
|
|
Type string `yaml:"type"`
|
|
Label string `yaml:"label"`
|
|
Items []RemoteItemConfigItem `yaml:"items"`
|
|
}
|
|
|
|
type RemoteItem struct {
|
|
Label string `yaml:"label"`
|
|
Items []RemoteItemConfig `yaml:"items"`
|
|
}
|
|
|
|
type Config struct {
|
|
Server ServerConfig `yaml:"server"`
|
|
Remote []RemoteItem `yaml:"remote"`
|
|
}
|
|
|
|
func createConfigFromFile(file string) (Config, error) {
|
|
data, err := os.ReadFile(file)
|
|
value := Config{}
|
|
|
|
if err != nil {
|
|
return value, err
|
|
}
|
|
|
|
err = yaml.Unmarshal(data, &value)
|
|
|
|
if err != nil {
|
|
return value, err
|
|
}
|
|
|
|
return value, nil
|
|
}
|