1
0
Files
gogodiscordo/core/config.go
2022-05-07 11:03:14 +02:00

38 lines
793 B
Go
Executable File

package core
import (
"io/ioutil"
"log"
"gopkg.in/yaml.v2"
)
// entity storing configuration values loaded from a yaml file
type Config struct {
Token string `yaml:"token"`
Name string `yaml:"name"`
Talkback[] struct {
Domain struct {
Name string `yaml:"name"`
Patterns []string `yaml:"patterns"`
Answers []string `yaml:"answers"`
} `yaml:"domain"`
} `yaml:"talkback"`
}
// loads the values from the yaml configuration file into the configuration register
func (c *Config) LoadConf() *Config {
yamlFile, err := ioutil.ReadFile("config.yaml")
if err != nil {
log.Printf("yamlFile.Get err #%v ", err)
}
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
log.Fatalf("Unmarshal: %v", err)
}
return c
}
// global configuration register
var ConfigRegister Config