合并pkg

This commit is contained in:
2024-12-18 23:38:28 +08:00
parent 5f5193fd70
commit 4551df34b6
43 changed files with 2978 additions and 13 deletions

31
pkg/myViper/viper.go Normal file
View File

@ -0,0 +1,31 @@
package myViper
import (
"fmt"
"github.com/spf13/viper"
)
type SimpleViper struct {
config interface{}
configType string
configName string
configPath string
}
func NewSimpleViper(config interface{}, configType string, configName string, configPath string) *SimpleViper {
return &SimpleViper{config: config, configType: configType, configName: configName, configPath: configPath}
}
func (t *SimpleViper) Apply() {
v := viper.New()
v.SetConfigFile(fmt.Sprintf("%s/%s.yaml", t.configPath, t.configName))
v.SetConfigType(t.configType)
err := v.ReadInConfig()
if err != nil {
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
if err := v.Unmarshal(t.config); err != nil {
panic(fmt.Errorf("Fatal Unmarshal error config file: %s \n", err))
}
}