Archived
2
0
This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
neko-custom/server/internal/preflight/config.go
2020-01-13 08:05:38 +00:00

49 lines
991 B
Go

package preflight
import (
"runtime"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
)
func Config(name string) {
config := viper.GetString("neko.config")
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().
Bool("debug", viper.GetBool("neko.debug")).
Str("logging", viper.GetString("neko.logs")).
Str("config", file).
Logger()
if file == "" {
logger.Warn().Msg("Preflight complete without config file")
} else {
logger.Info().Msg("Preflight complete")
}
}