webservice/config/pkg.go

58 lines
768 B
Go
Raw Normal View History

2024-01-04 20:19:47 +01:00
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
2024-01-04 20:19:47 +01:00
}
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
}
2024-05-22 07:58:29 +02:00
func (config *Config) ParseApplicationConfig(v any) {
yStr, _ := yaml.Marshal(config.Application)
yaml.Unmarshal(yStr, &v)
}