-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.go
45 lines (35 loc) · 1022 Bytes
/
configure.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
package main
import (
"errors"
"strings"
"github.com/spf13/viper"
)
func configure() error {
defaults()
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.AddConfigPath("/etc/it-sektionen")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()
viper.SetConfigName("kvitto-store")
if err := viper.ReadInConfig(); err != nil {
var configFileAlreadyExistsError viper.ConfigFileNotFoundError
if errors.As(err, &configFileAlreadyExistsError) {
// Write the default config to current directory if no file was found
_ = viper.SafeWriteConfig()
}
return err
}
return nil
}
func defaults() {
// MQTT settings
viper.SetDefault("mqtt.broker", "localhost:1883")
viper.SetDefault("mqtt.client_id", "kvitto-store")
viper.SetDefault("mqtt.timeout", "1m")
// Influx settings
viper.SetDefault("influx.url", "http://localhost:8086")
viper.SetDefault("influx.token", "suersecret")
viper.SetDefault("influx.bucket", "kvitto")
viper.SetDefault("influx.org", "smn")
}