Browse Source

Put config file search path in one place

tags/v0.4.9
Sam Willcocks 5 months ago
parent
commit
a12b6ea482
1 changed files with 11 additions and 4 deletions
  1. 11
    4
      main.go

+ 11
- 4
main.go View File

@@ -12,6 +12,7 @@ import (
12 12
 	"github.com/thoj/go-ircevent"
13 13
 	"os"
14 14
 	"os/signal"
15
+	"strings"
15 16
 	"syscall"
16 17
 )
17 18
 
@@ -20,6 +21,12 @@ var log = loggo.GetLogger("main")
20 21
 var branch string
21 22
 var revision string
22 23
 
24
+var CONFIG_FILE_LOCATIONS = []string{
25
+	"/etc",
26
+	"/run/secrets",
27
+	".",
28
+}
29
+
23 30
 type IRCCat struct {
24 31
 	auth_channel string
25 32
 	channels     mapset.Set
@@ -40,15 +47,15 @@ func main() {
40 47
 		viper.SetConfigFile(*configFile)
41 48
 	} else {
42 49
 		viper.SetConfigName("irccat")
43
-		viper.AddConfigPath("/run/secrets")
44
-		viper.AddConfigPath("/etc")
45
-		viper.AddConfigPath(".")
50
+		for _, p := range CONFIG_FILE_LOCATIONS {
51
+			viper.AddConfigPath(p)
52
+		}
46 53
 	}
47 54
 	var err error
48 55
 
49 56
 	err = viper.ReadInConfig()
50 57
 	if err != nil {
51
-		log.Errorf("Error reading config file - exiting. I'm looking for irccat.[json|yaml|toml|hcl] in . or /etc")
58
+		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, ", "))
52 59
 		return
53 60
 	}
54 61
 

Loading…
Cancel
Save