init
This commit is contained in:
31
pkg/myViper/viper.go
Normal file
31
pkg/myViper/viper.go
Normal 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))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user