From 8b2d22a93bccb1d4802d9c74c7a5071662023509 Mon Sep 17 00:00:00 2001 From: Tyler Date: Wed, 30 Mar 2022 21:33:35 -0400 Subject: [PATCH] Add config path flag for non-docker running --- main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index eae8975..074b8c2 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "flag" "github.com/chi-middleware/logrus-logger" "github.com/go-chi/chi/v5" "github.com/oschwald/maxminddb-golang" @@ -41,6 +42,10 @@ type City struct { } `maxminddb:"location"` } +var ( + configFlag = flag.String("config", "", "configuration file path") +) + func main() { viper.SetDefault("bind", ":8080") @@ -49,7 +54,12 @@ func main() { viper.AddConfigPath("/etc/dlrouter/") // path to look for the config file in viper.AddConfigPath("$HOME/.dlrouter") // call multiple times to add many search paths viper.AddConfigPath(".") // optionally look for config in the working directory - err := viper.ReadInConfig() // Find and read the config file + + if *configFlag != "" { + viper.SetConfigFile(*configFlag) + } + + err := viper.ReadInConfig() // Find and read the config file if err != nil { // Handle errors reading the config file log.WithError(err).Fatalln("Unable to load config file")