32 lines
770 B
Go
32 lines
770 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"github.com/sirupsen/logrus"
|
||
|
"github.com/spf13/viper"
|
||
|
)
|
||
|
|
||
|
func initConfig() error {
|
||
|
viper.SetDefault("host", "[::]")
|
||
|
viper.SetDefault("port", 8080)
|
||
|
viper.SetDefault("db_path", "bin.db")
|
||
|
viper.SetDefault("smtp.enabled", false)
|
||
|
viper.SetDefault("user.registration_enabled", false)
|
||
|
|
||
|
viper.SetConfigName("config")
|
||
|
viper.SetConfigType("toml")
|
||
|
viper.AddConfigPath("/etc/bin")
|
||
|
viper.AddConfigPath("$HOME/.config/bin")
|
||
|
viper.AddConfigPath("$XDG_CONFIG_HOME/bin")
|
||
|
viper.AddConfigPath(".")
|
||
|
|
||
|
if err := viper.ReadInConfig(); err != nil {
|
||
|
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||
|
logrus.Warnln("No config file found.")
|
||
|
} else {
|
||
|
logrus.WithError(err).Errorln("Config file found but could not read it.")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|