move config & logging packages into internal submodules
This commit is contained in:
parent
e525b7ff3b
commit
450d425b04
5 changed files with 62 additions and 38 deletions
53
config.go
53
config.go
|
|
@ -1,53 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var appConfig *AppConfig
|
||||
|
||||
type AppConfig struct {
|
||||
LogFile string `yaml:"log_file"`
|
||||
LogDir string `yaml:"log_dir"`
|
||||
LogMaxSizeMB int `yaml:"log_max_size_mb"`
|
||||
LogMaxBackups int `yaml:"log_max_backups"`
|
||||
LogMaxAgeDays int `yaml:"log_max_age_days"`
|
||||
LogCompression bool `yaml:"log_compression"`
|
||||
LogAddSource bool `yaml:"log_add_source"`
|
||||
}
|
||||
|
||||
func parseConfigs() error {
|
||||
setDefaults()
|
||||
|
||||
// automatically populate config with any matching environment vars
|
||||
viper.SetEnvPrefix("BB")
|
||||
viper.AutomaticEnv()
|
||||
|
||||
viper.SetConfigName("config")
|
||||
viper.SetConfigType("yaml")
|
||||
viper.AddConfigPath(".")
|
||||
|
||||
err := viper.ReadInConfig()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading configs: %s", err)
|
||||
}
|
||||
|
||||
err = viper.Unmarshal(&appConfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error unmarshaling configs: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func setDefaults() {
|
||||
viper.SetDefault("LogFile", "bingobot.log")
|
||||
viper.SetDefault("LogDir", "log")
|
||||
viper.SetDefault("LogMaxSizeMB", 500)
|
||||
viper.SetDefault("LogMaxBackups", 3)
|
||||
viper.SetDefault("LogMaxAgeDays", 365)
|
||||
viper.SetDefault("LogCompression", false)
|
||||
viper.SetDefault("LogAddSource", true)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue