36 lines
477 B
Go
36 lines
477 B
Go
package config
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"log"
|
|
|
|
yaml "gopkg.in/yaml.v3"
|
|
)
|
|
|
|
const CONFIGFILE = "config.yaml"
|
|
|
|
const DEFAULTCONFIG = `
|
|
host: "127.0.0.1"
|
|
port: 5000
|
|
`
|
|
|
|
type TrackmaniaConfig struct {
|
|
Host string
|
|
Port int
|
|
}
|
|
|
|
type AppConfig struct {
|
|
Trackmania TrackmaniaConfig
|
|
}
|
|
|
|
func (c *AppConfig) ReadConfig() {
|
|
yamlFile, err := ioutil.ReadFile(CONFIGFILE)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
err = yaml.Unmarshal([]byte(yamlFile), c)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|