package apollo import ( "fmt" "git.bvbej.com/bvbej/base-golang/pkg/env" "github.com/spf13/viper" "github.com/zouyx/agollo/v4" "github.com/zouyx/agollo/v4/component/log" agolloConfig "github.com/zouyx/agollo/v4/env/config" ) func GetApolloConfig(appId, secret string, config interface{}) { namespace := env.Active().Value() + ".yaml" ac := &agolloConfig.AppConfig{ AppID: appId, Cluster: "dev", IP: "https://config.bvbej.com", NamespaceName: namespace, IsBackupConfig: true, Secret: secret, } agollo.SetLogger(&log.DefaultLogger{}) client, err := agollo.StartWithConfig(func() (*agolloConfig.AppConfig, error) { return ac, nil }) if err != nil { panic(fmt.Sprintf("get config error:[%s]", err)) } viper.SetConfigType("yaml") client.GetConfigCache(ac.NamespaceName).Range(func(key, value interface{}) bool { viper.Set(key.(string), value) return true }) if err = viper.Unmarshal(config); err != nil { panic(fmt.Sprintf("unmarshal config error:[%s]", err)) } }