123456789101112131415161718192021222324 |
- package config
- import (
- "fmt"
- "github.com/mitchellh/mapstructure"
- "github.com/spf13/viper"
- )
- func Initialize(path string, cfgStruct interface{}) error {
- dir := fmt.Sprintf("./config/%s", path)
- // dir = fmt.Sprintf("D:\\project\\golangNew\\kpt-tmr-group\\config\\%s", path)
- viper.SetConfigType("yaml")
- viper.SetConfigFile(dir)
- if err := viper.ReadInConfig(); err != nil {
- return err
- }
- if err := viper.Unmarshal(&cfgStruct, func(c *mapstructure.DecoderConfig) {
- c.TagName = "yaml"
- }); err != nil {
- return err
- }
- return nil
- }
|