2023-06-15 07:24:23 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
// External
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
|
|
|
|
// Standard
|
2023-06-18 20:13:35 +02:00
|
|
|
"errors"
|
2023-06-15 07:24:23 +02:00
|
|
|
"io/ioutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
Websocket struct {
|
|
|
|
Domains []string
|
|
|
|
}
|
|
|
|
|
|
|
|
Database struct {
|
|
|
|
Host string
|
|
|
|
Port int
|
|
|
|
Name string
|
|
|
|
Username string
|
|
|
|
Password string
|
|
|
|
}
|
2023-06-17 09:11:14 +02:00
|
|
|
|
2023-06-19 15:02:52 +02:00
|
|
|
Application struct {
|
|
|
|
StaticDir string
|
|
|
|
}
|
|
|
|
|
2023-06-17 09:11:14 +02:00
|
|
|
Session struct {
|
|
|
|
DaysValid int
|
|
|
|
}
|
2023-06-15 07:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2023-06-18 20:13:35 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.Session.DaysValid == 0 {
|
|
|
|
err = errors.New("Configuration: session.daysvalid needs to be higher than 0.")
|
|
|
|
}
|
|
|
|
|
2023-06-15 07:24:23 +02:00
|
|
|
return
|
|
|
|
}
|