1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-11-03 04:27:16 -05:00
neonmodem/config/config.go
2022-12-29 14:32:48 -05:00

56 lines
976 B
Go

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
}