agollo

package module
v4.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2021 License: Apache-2.0 Imports: 25 Imported by: 0

README

Agollo - Go Client for Apollo

golang Build Status Go Report Card codebeat badge Coverage Status License GoDoc GitHub release 996.icu

方便Golang接入配置中心框架 Apollo 所开发的Golang版本客户端。

Features

  • 支持多 IP、AppID、namespace
  • 实时同步配置
  • 灰度配置
  • 延迟加载(运行时)namespace
  • 客户端,配置文件容灾
  • 自定义日志,缓存组件
  • 支持配置访问秘钥

Usage

快速入门

导入 agollo
go get -u github.com/Kayshen-X/agollo/v4@latest
启动 agollo
package main

import (
	"fmt"
	"github.com/Kayshen-X/agollo/v4"
	"github.com/Kayshen-X/agollo/v4/env/config"
)

func main() {
	c := &config.AppConfig{
		AppID:          "testApplication_yang",
		Cluster:        "dev",
		IP:             "http://106.54.227.205:8080",
		NamespaceName:  "dubbo",
		IsBackupConfig: true,
		Secret:         "6ce3ff7e96a24335a9634fe9abca6d51",
	}

	agollo.SetLogger(&DefaultLogger{})

	client, _ := agollo.StartWithConfig(func() (*config.AppConfig, error) {
		return c, nil
	})
	fmt.Println("初始化Apollo配置成功")

	//Use your apollo key to test
	cache := client.GetConfigCache(c.NamespaceName)
	value, _ := cache.Get("key")
	fmt.Println(value)
}

更多用法

使用Demoagollo_demo

其他语言agollo-agent 做本地agent接入,如:PHP

欢迎查阅 Wiki 或者 godoc 获取更多有用的信息

如果你觉得该工具还不错或者有问题,一定要让我知道,可以发邮件或者留言

User

Contribution

License

The project is licensed under the Apache 2 license.

Reference

Apollo : https://github.com/ctripcorp/apollo

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetBackupFileHandler

func SetBackupFileHandler(file file.FileHandler)

SetBackupFileHandler 设置自定义备份文件处理组件

func SetCache

func SetCache(cacheFactory agcache.CacheFactory)

SetCache 设置自定义cache组件

func SetLoadBalance

func SetLoadBalance(loadBalance cluster.LoadBalance)

SetLoadBalance 设置自定义负载均衡组件

func SetLogger

func SetLogger(loggerInterface log.LoggerInterface)

SetLogger 设置自定义logger组件

func SetSignature

func SetSignature(auth auth.HTTPAuth)

SetSignature 设置自定义 http 授权控件

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client apollo 客户端实例

func Start

func Start() (*Client, error)

Start 根据默认文件启动

func StartWithConfig

func StartWithConfig(loadAppConfig func() (*config.AppConfig, error)) (*Client, error)

StartWithConfig 根据配置启动

func (*Client) AddChangeListener

func (c *Client) AddChangeListener(listener storage.ChangeListener)

AddChangeListener 增加变更监控

func (*Client) GetApolloConfigCache

func (c *Client) GetApolloConfigCache() agcache.CacheInterface

GetApolloConfigCache 获取默认namespace的apollo配置

func (*Client) GetBoolValue

func (c *Client) GetBoolValue(key string, defaultValue bool) bool

GetBoolValue 获取bool 配置值

func (*Client) GetChangeListeners

func (c *Client) GetChangeListeners() *list.List

GetChangeListeners 获取配置修改监听器列表

func (*Client) GetConfig

func (c *Client) GetConfig(namespace string) *storage.Config

GetConfig 根据namespace获取apollo配置

func (*Client) GetConfigAndInit

func (c *Client) GetConfigAndInit(namespace string) *storage.Config

GetConfigAndInit 根据namespace获取apollo配置

func (*Client) GetConfigCache

func (c *Client) GetConfigCache(namespace string) agcache.CacheInterface

GetConfigCache 根据namespace获取apollo配置的缓存

func (*Client) GetDefaultConfigCache

func (c *Client) GetDefaultConfigCache() agcache.CacheInterface

GetDefaultConfigCache 获取默认缓存

func (*Client) GetFloatValue

func (c *Client) GetFloatValue(key string, defaultValue float64) float64

GetFloatValue 获取float配置值

func (*Client) GetIntSliceValue

func (c *Client) GetIntSliceValue(key string, defaultValue []int) []int

GetIntSliceValue 获取[]int 配置值

func (*Client) GetIntValue

func (c *Client) GetIntValue(key string, defaultValue int) int

GetIntValue 获取int配置值

func (*Client) GetStringSliceValue

func (c *Client) GetStringSliceValue(key string, defaultValue []string) []string

GetStringSliceValue 获取[]string 配置值

func (*Client) GetStringValue

func (c *Client) GetStringValue(key string, defaultValue string) string

GetStringValue 获取string配置值

func (*Client) GetValue

func (c *Client) GetValue(key string) string

GetValue 获取配置

func (*Client) RemoveChangeListener

func (c *Client) RemoveChangeListener(listener storage.ChangeListener)

RemoveChangeListener 增加变更监控

func (*Client) UseEventDispatch

func (c *Client) UseEventDispatch()

UseEventDispatch 添加为某些key分发event功能

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL