携程Apollo Golang版客户端
go get -u github.com/reaperhero/apollo-client-go
- 实时同步配置,配置改动监听
- 配置文件容灾
- 支持多namespace, cluster
- 客户端SLB
- 支持通过 ACCESSKEY_SECRET 来实现 client 安全访问
- 支持自定义签名认证
此示例场景适用于程序启动时读取一次。不会额外启动goroutine同步配置
package main
import (
"fmt"
agollo "github.com/reaperhero/apollo-client-go"
)
var (
configServerURL = []string{"https://192.168.50.24:8080"}
configAppid = "testId"
configNameSpaces = []string{"application", "mysql"}
)
func main() {
client, _ := agollo.NewAgolloOnce(
configServerURL,
configAppid,
agollo.WithNameSpaces(configNameSpaces),
agollo.WithLogger(agollo.NewLogger(agollo.LoggerWriter(os.Stdout))),
agollo.AutoFetchOnCacheMiss(),
agollo.FailTolerantOnBackupExists(),
)
// 一次性获取
for n, v := range client.GetAllNameSpaceValue() {
fmt.Println(n, v)
}
// 监听变化
errCh := client.Start()
respCh := client.Watch()
for {
select {
case err := <-errCh:
fmt.Println(err)
case resp :=<-respCh:
fmt.Println(resp)
}
}
}