58 lines
768 B
Go
58 lines
768 B
Go
package config
|
|
|
|
import (
|
|
// External
|
|
"gopkg.in/yaml.v3"
|
|
|
|
// Standard
|
|
"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
|
|
}
|
|
|
|
Application any
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (config *Config) ParseApplicationConfig(v any) {
|
|
yStr, _ := yaml.Marshal(config.Application)
|
|
yaml.Unmarshal(yStr, &v)
|
|
}
|