-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig.go
45 lines (36 loc) · 1.24 KB
/
config.go
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
41
42
43
44
45
/*
This function sets up the configuration file
*/
package main
import (
"fmt"
"github.com/spf13/viper"
)
func initConfig() {
viper.SetConfigName("evedb") // name of config file (without extension)
viper.SetConfigType("yaml") // REQUIRED if the config file does not have the extension in the name
viper.AddConfigPath(".") // optionally look for config in the working directory
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
fmt.Println("Config file missing. Using defaults.")
//Set Defaults
viper.SetDefault("log-level", "Info")
viper.SetDefault("db-host", "127.0.0.1")
viper.SetDefault("db-port", "3306")
viper.SetDefault("db-user", "evemu")
viper.SetDefault("db-pass", "evemu")
viper.SetDefault("db-database", "evemu")
viper.SetDefault("migrations-dir", "migrations")
viper.SetDefault("base-dir", "base")
viper.SetDefault("dungeon-dir", "dungeons")
var seededRegions [1]string
seededRegions[0] = "Derelik"
viper.SetDefault("seed-regions", seededRegions)
viper.SetDefault("seed-saturation", 80)
//Write configuration file to disk
viper.WriteConfigAs("./evedb.yaml")
} else {
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
}
}