-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit.go
More file actions
40 lines (32 loc) · 754 Bytes
/
init.go
File metadata and controls
40 lines (32 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"flag"
"fmt"
"github.com/spf13/viper"
"os"
)
var cfgPtr, joinPtr *string // late-binding for configuration location
func ReadConfig() {
err := viper.ReadInConfig()
if err != nil {
if os.Getenv("TESTING") == "" {
log.Fatal(fmt.Errorf("fatal error config file: %s \n", err))
}
}
}
func init() {
// support ara.* files
viper.SetConfigName("yzma")
// Three main locations to look for config files
viper.AddConfigPath(".")
viper.AddConfigPath("$HOME/.yzma")
viper.AddConfigPath("/etc/yzma/")
// Allow for a custom location to be set
cfgPtr = flag.String("c", "", "config file")
joinPtr = flag.String("j", "", "join peer")
flag.Parse()
if *cfgPtr != "" {
viper.SetConfigFile(*cfgPtr)
}
ReadConfig()
}