36 lines
625 B
Go
36 lines
625 B
Go
package main
|
|
|
|
import "git.sr.ht/~emersion/go-scfg"
|
|
|
|
type config struct {
|
|
HTTPAddress string
|
|
LogLevel string
|
|
}
|
|
|
|
func readConfig(path string) (*config, error) {
|
|
cfg, err := scfg.Load(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
config := new(config)
|
|
// Set default values
|
|
config.HTTPAddress = "127.0.0.1:8080"
|
|
config.LogLevel = "info"
|
|
|
|
d := cfg.Get("log-level")
|
|
if d != nil {
|
|
if err := d.ParseParams(&config.LogLevel); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
d = cfg.Get("http-address")
|
|
if d != nil {
|
|
if err := d.ParseParams(&config.HTTPAddress); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return config, nil
|
|
}
|