Tidy up main
This commit is contained in:
parent
547063de2e
commit
6c0000d409
@ -37,41 +37,10 @@ var (
|
||||
)
|
||||
|
||||
func main() {
|
||||
var (
|
||||
err error
|
||||
)
|
||||
|
||||
C = bot.NewConfig()
|
||||
|
||||
flag.Bool("debug", false, "enable debug logging")
|
||||
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
|
||||
pflag.Parse()
|
||||
viper.BindPFlags(pflag.CommandLine)
|
||||
|
||||
if viper.GetBool("debug") {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
}
|
||||
setupConfig()
|
||||
|
||||
lib.SeedMathRand()
|
||||
|
||||
viper.SetEnvPrefix("BEEPBOOP")
|
||||
viper.AutomaticEnv()
|
||||
viper.SetConfigName("config")
|
||||
viper.SetConfigType("toml")
|
||||
viper.AddConfigPath(".")
|
||||
err = viper.ReadInConfig()
|
||||
viper.BindEnv("DISCORD_TOKEN")
|
||||
viper.BindEnv("OPEN_WEATHER_MAP_TOKEN")
|
||||
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
|
||||
log.Fatalf("fatal error config file: %v", err)
|
||||
}
|
||||
|
||||
err = viper.Unmarshal(&C)
|
||||
if err != nil {
|
||||
log.Fatalf("unable to decode into struct: %v", err)
|
||||
}
|
||||
|
||||
if C.DiscordToken == "" {
|
||||
log.Fatalf("Discord token is not set")
|
||||
}
|
||||
@ -103,3 +72,39 @@ func main() {
|
||||
|
||||
log.Info("Shutting down")
|
||||
}
|
||||
|
||||
func setupConfig() {
|
||||
var err error
|
||||
|
||||
C = bot.NewConfig()
|
||||
|
||||
flag.Bool("debug", false, "enable debug logging")
|
||||
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
|
||||
pflag.Parse()
|
||||
viper.BindPFlags(pflag.CommandLine)
|
||||
|
||||
if viper.GetBool("debug") {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
}
|
||||
|
||||
viper.SetEnvPrefix("BEEPBOOP")
|
||||
viper.AutomaticEnv()
|
||||
|
||||
viper.SetConfigName("config")
|
||||
viper.SetConfigType("toml")
|
||||
viper.AddConfigPath(".")
|
||||
|
||||
err = viper.ReadInConfig()
|
||||
|
||||
viper.BindEnv("DISCORD_TOKEN")
|
||||
viper.BindEnv("OPEN_WEATHER_MAP_TOKEN")
|
||||
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
|
||||
log.Fatalf("fatal error config file: %v", err)
|
||||
}
|
||||
|
||||
err = viper.Unmarshal(&C)
|
||||
if err != nil {
|
||||
log.Fatalf("unable to decode into struct: %v", err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user