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) 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 }