|
@@ -3,46 +3,57 @@ package config
|
|
|
import "github.com/spf13/viper"
|
|
|
|
|
|
type config struct {
|
|
|
- viper *viper.Viper
|
|
|
+ Viper *viper.Viper
|
|
|
+}
|
|
|
+
|
|
|
+func New() *config {
|
|
|
+ var c config
|
|
|
+
|
|
|
+ c.Viper = viper.New()
|
|
|
+ c.Viper.SetConfigName(defaultName) //defaultName := lib.AppName()
|
|
|
+ c.Viper.SetConfigType(defaultConfigType)
|
|
|
+ c.Viper.AddConfigPath(defaultPath)
|
|
|
+
|
|
|
+ return &c
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
+ 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()
|
|
|
+ return c.Viper.ReadInConfig()
|
|
|
}
|
|
|
|
|
|
func (c *config) Store() error {
|
|
|
- return c.viper.SafeWriteConfig()
|
|
|
+ return c.Viper.SafeWriteConfig()
|
|
|
}
|
|
|
|
|
|
func (c *config) Register(module, key string, value any) {
|
|
|
- c.viper.SetDefault(module+"."+key, value)
|
|
|
+ c.Viper.SetDefault(module+"."+key, value)
|
|
|
}
|
|
|
|
|
|
func (c *config) GetBool(module, key string) bool {
|
|
|
- return c.viper.GetBool(module + "." + key)
|
|
|
+ return c.Viper.GetBool(module + "." + key)
|
|
|
}
|
|
|
|
|
|
func (c *config) GetString(module, key string) string {
|
|
|
- return c.viper.GetString(module + "." + key)
|
|
|
+ return c.Viper.GetString(module + "." + key)
|
|
|
}
|
|
|
|
|
|
func (c *config) GetInt(module, key string) int {
|
|
|
- return c.viper.GetInt(module + "." + key)
|
|
|
+ return c.Viper.GetInt(module + "." + key)
|
|
|
}
|
|
|
|
|
|
func (c *config) GetFloat(module, key string) float64 {
|
|
|
- return c.viper.GetFloat64(module + "." + key)
|
|
|
+ return c.Viper.GetFloat64(module + "." + key)
|
|
|
}
|
|
|
|
|
|
func (c *config) GetStringSlice(module string, key string) []string {
|