-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.go
41 lines (35 loc) · 949 Bytes
/
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
package main
import (
"fmt"
"github.com/spf13/viper"
)
type config struct {
SelectForeground string `mapstructure:"select_foreground"`
SelectBackground string `mapstructure:"select_background"`
Theme string `mapstructure:"theme"`
}
// Config is a global struct holding the configuration
var Config config
// LoadConfig finds and unmarshals configuration
func LoadConfig() (err error) {
viper.SetConfigName("config")
viper.SetConfigType("yml")
viper.AddConfigPath("$HOME/.config/make-tui")
setDefaults()
err = viper.ReadInConfig()
if err != nil {
// Do not panic if config is not found.
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
err = nil
} else {
panic(fmt.Errorf("Fatal error config file: %s", err))
}
}
viper.Unmarshal(&Config)
return
}
func setDefaults() {
viper.SetDefault("select_foreground", "white")
viper.SetDefault("select_background", "black")
viper.SetDefault("theme", "vim")
}