2020-01-13 21:05:38 +13:00
|
|
|
package preflight
|
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime"
|
|
|
|
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Config(name string) {
|
2020-01-14 12:12:55 +13:00
|
|
|
config := viper.GetString("config")
|
2020-01-13 21:05:38 +13:00
|
|
|
|
|
|
|
if config != "" {
|
|
|
|
viper.SetConfigFile(config) // Use config file from the flag.
|
|
|
|
} else {
|
|
|
|
if runtime.GOOS == "linux" {
|
|
|
|
viper.AddConfigPath("/etc/neko/")
|
|
|
|
}
|
|
|
|
|
|
|
|
viper.AddConfigPath(".")
|
|
|
|
viper.SetConfigName(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
viper.SetEnvPrefix("NEKO")
|
|
|
|
viper.AutomaticEnv() // read in environment variables that match
|
|
|
|
|
|
|
|
if err := viper.ReadInConfig(); err != nil {
|
|
|
|
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
|
|
|
|
log.Error().Err(err)
|
|
|
|
}
|
|
|
|
if config != "" {
|
|
|
|
log.Error().Err(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
file := viper.ConfigFileUsed()
|
|
|
|
logger := log.With().
|
2020-01-14 12:12:55 +13:00
|
|
|
Bool("debug", viper.GetBool("debug")).
|
|
|
|
Str("logging", viper.GetString("logs")).
|
2020-01-13 21:05:38 +13:00
|
|
|
Str("config", file).
|
|
|
|
Logger()
|
|
|
|
|
|
|
|
if file == "" {
|
|
|
|
logger.Warn().Msg("Preflight complete without config file")
|
|
|
|
} else {
|
|
|
|
logger.Info().Msg("Preflight complete")
|
|
|
|
}
|
|
|
|
}
|