32 lines
775 B
Go
32 lines
775 B
Go
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))
|
|
}
|
|
}
|