Notes/config.go
2023-06-21 23:52:21 +02:00

54 lines
769 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
}
Application struct {
Directories struct {
Static string
Upload 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
}