参考文章:很重要的
初探Apollo远程服务配置中心_阿波罗_Barry Yan_InfoQ写作社区
apollo的配置流程:
配位完了 就在客户端中可以调用了
package main
import (
"fmt"
"github.com/apolloconfig/agollo/v4"
"github.com/apolloconfig/agollo/v4/env/config"
)
//AppId: 10038
//应用名称: apollo-server
//部门: 样例部门2(TEST2)
//负责人: apollo(apollo)
//邮箱: apollo@acme.com
func main() {
c := &config.AppConfig{
AppID: "10038",
Cluster: "dev",
IP: "http://127.0.0.1:8080",
//NamespaceName: "TEST1.go_test_1201",
NamespaceName: "application",
IsBackupConfig: true,
Secret: "56ffb5eb1f6c4aba9ab008508a123650",
}
client, err := agollo.StartWithConfig(func() (*config.AppConfig, error) {
return c, nil
})
if err != nil {
fmt.Println("初始化Apollo失败")
} else {
fmt.Println("初始化Apollo配置成功")
}
//Use your apollo key to test
cache := client.GetConfigCache(c.NamespaceName)
value, _ := cache.Get("happy girl")
fmt.Println(value)
}