package config import "github.com/spf13/viper" type config struct { viper *viper.Viper } func NewConfig(name, suffix, path string) *config { var c config c.viper = viper.New() c.viper.SetConfigName(name) //defaultName := lib.AppName() c.viper.SetConfigType(suffix) c.viper.AddConfigPath(path) return &c } func (c *config) Load() error { return c.viper.ReadInConfig() } func (c *config) Store() error { return c.viper.SafeWriteConfig() } func (c *config) Register(module, key string, value any) { c.viper.SetDefault(module+"."+key, value) } func (c *config) GetBool(module, key string) bool { return c.viper.GetBool(module + "." + key) } func (c *config) GetString(module, key string) string { return c.viper.GetString(module + "." + key) } func (c *config) GetInt(module, key string) int { return c.viper.GetInt(module + "." + key) } func (c *config) GetFloat(module, key string) float64 { return c.viper.GetFloat64(module + "." + key) } func (c *config) GetStringSlice(module string, key string) []string { return viper.GetStringSlice(module + "." + key) } func (c *config) Set(module, key string, value any) { viper.Set(module+"."+key, value) }