Notes/config.go
Magnus Åhall 1812873e33 wip
2023-06-18 20:13:35 +02:00

47 lines
682 B
Go

package main
import (
// External
"gopkg.in/yaml.v3"
// Standard
"errors"
"io/ioutil"
)
type Config struct {
Websocket struct {
Domains []string
}
Database struct {
Host string
Port int
Name string
Username string
Password string
}
Session struct {
DaysValid int
}
}
func ConfigRead(filename string) (config Config, err error) {
var rawConfigData []byte
rawConfigData, err = ioutil.ReadFile(filename)
if err != nil { return }
err = yaml.Unmarshal(rawConfigData, &config)
if err != nil {
return
}
if config.Session.DaysValid == 0 {
err = errors.New("Configuration: session.daysvalid needs to be higher than 0.")
}
return
}