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