1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-06-09 06:20:43 +00:00

Added config

This commit is contained in:
マリウス 2022-12-29 14:32:48 -05:00
parent 70cc3b63fc
commit 3d924e808b
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F

55
config/config.go Normal file
View 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
}