package config import ( "fmt" "os" "github.com/mitchellh/mapstructure" "github.com/spf13/viper" ) func Initialize(path string, cfgStruct interface{}) error { dir := fmt.Sprintf("%s/config/%s", os.Getenv("GO_WORK_DIR"), 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 }