webservice/config/pkg.go
2024-01-04 20:19:47 +01:00

56 lines
754 B
Go

package config
import (
// External
"gopkg.in/yaml.v3"
// Standard
"errors"
"os"
)
type DatabaseDetails struct {
Host string
Port int
Name string
Username string
Password string
}
type Config struct {
Network struct {
Address string
Port int
}
Websocket struct {
Domains []string
}
Database DatabaseDetails
Session struct {
DaysValid int
}
}
func New(filename string) (config Config, err error) {
var rawConfigData []byte
rawConfigData, err = os.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
}