mirror of
https://github.com/mrusme/neonmodem.git
synced 2025-02-02 15:07:59 -05:00
Added config
This commit is contained in:
parent
70cc3b63fc
commit
3d924e808b
55
config/config.go
Normal file
55
config/config.go
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
StatusOnline int8 = iota
|
||||||
|
StatusOffline = 2
|
||||||
|
StatusNoNewSyncs = 3
|
||||||
|
)
|
||||||
|
|
||||||
|
var VERSION string
|
||||||
|
|
||||||
|
type ServiceStatus int8
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Debug string
|
||||||
|
|
||||||
|
Systems []struct {
|
||||||
|
Type string
|
||||||
|
Config map[string]interface{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Load() (Config, error) {
|
||||||
|
viper.SetDefault("Debug", "true")
|
||||||
|
|
||||||
|
viper.SetConfigName("gobbs.toml")
|
||||||
|
viper.SetConfigType("toml")
|
||||||
|
viper.AddConfigPath("/etc/")
|
||||||
|
viper.AddConfigPath("$XDG_CONFIG_HOME/")
|
||||||
|
viper.AddConfigPath("$HOME/.config/")
|
||||||
|
viper.AddConfigPath("$HOME/")
|
||||||
|
viper.AddConfigPath(".")
|
||||||
|
|
||||||
|
viper.SetEnvPrefix("gobbs")
|
||||||
|
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||||
|
viper.AutomaticEnv()
|
||||||
|
|
||||||
|
if err := viper.ReadInConfig(); err != nil {
|
||||||
|
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
|
||||||
|
return Config{}, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var config Config
|
||||||
|
if err := viper.Unmarshal(&config); err != nil {
|
||||||
|
return Config{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return config, nil
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user