Skip to content

reaperhero/apollo-client-go

Repository files navigation

Agollo - Go Client for Apollo

Build Status Go Report Card codebeat badge golang GoDoc GitHub release License

携程Apollo Golang版客户端

快速开始

获取安装

go get -u github.com/reaperhero/apollo-client-go

Features

  • 实时同步配置,配置改动监听
  • 配置文件容灾
  • 支持多namespace, cluster
  • 客户端SLB
  • 支持通过 ACCESSKEY_SECRET 来实现 client 安全访问
  • 支持自定义签名认证

示例

读取配置

此示例场景适用于程序启动时读取一次。不会额外启动goroutine同步配置

package main

import (
	"fmt"

	agollo "github.com/reaperhero/apollo-client-go"
)

var (
	configServerURL  = []string{"http://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)
		}
	}
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages