Skip to content

Commit

Permalink
Put config file search path in one place
Browse files Browse the repository at this point in the history
  • Loading branch information
wlcx committed Dec 8, 2023
1 parent 97397a7 commit e137ebf
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/thoj/go-ircevent"
"os"
"os/signal"
"strings"
"syscall"
)

Expand All @@ -20,6 +21,12 @@ var log = loggo.GetLogger("main")
var branch string
var revision string

var CONFIG_FILE_LOCATIONS = []string{
"/etc",
"/var/secrets",
".",
}

type IRCCat struct {
auth_channel string
channels mapset.Set
Expand All @@ -40,15 +47,15 @@ func main() {
viper.SetConfigFile(*configFile)
} else {
viper.SetConfigName("irccat")
viper.AddConfigPath("/run/secrets")
viper.AddConfigPath("/etc")
viper.AddConfigPath(".")
for _, p := range CONFIG_FILE_LOCATIONS {
viper.AddConfigPath(p)
}
}
var err error

err = viper.ReadInConfig()
if err != nil {
log.Errorf("Error reading config file - exiting. I'm looking for irccat.[json|yaml|toml|hcl] in . or /etc")
log.Errorf("Error reading config file - exiting. I'm looking for irccat.[json|yaml|toml|hcl] in one of %s", strings.Join(CONFIG_FILE_LOCATIONS, ", "))
return
}

Expand Down

0 comments on commit e137ebf

Please sign in to comment.