agollo

package module
v5.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: Apache-2.0 Imports: 26 Imported by: 8

README

Agollo - Go Client for Apollo

English | 中文

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

A Golang client for the configuration center framework Apollo.

Features

  • Support for multiple IPs, AppIDs, and namespaces
  • Real-time configuration synchronization
  • Gray release configuration
  • Lazy loading (runtime) namespaces
  • Client-side and configuration file fallback
  • Customizable logger and cache components
  • Support for configuration access keys

Usage

Quick Start

Import agollo
go get -u github.com/apolloconfig/agollo/v5@latest
Initialize agollo
package main

import (
	"fmt"

	"github.com/apolloconfig/agollo/v5"
	"github.com/apolloconfig/agollo/v5/env/config"
)

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

	client, _ := agollo.StartWithConfig(func() (*config.AppConfig, error) {
		return c, nil
	})
	fmt.Println("Apollo configuration initialized successfully")

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

More Examples

Demo Project: agollo_demo

Other Languages:: Use agollo-agent as a local agent for languages like PHP.

Check out our Wiki or godoc for more information.

If you find this tool useful or encounter any issues, please let me know via email or by creating an issue

User

Contribution

License

The project is licensed under the Apache 2 license.

Reference

Apollo: https://github.com/apolloconfig/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 interface {
	GetConfig(namespace string) *storage.Config
	GetConfigAndInit(namespace string) *storage.Config
	GetConfigCache(namespace string) agcache.CacheInterface
	GetDefaultConfigCache() agcache.CacheInterface
	GetApolloConfigCache() agcache.CacheInterface
	GetValue(key string) string
	GetStringValue(key string, defaultValue string) string
	GetIntValue(key string, defaultValue int) int
	GetFloatValue(key string, defaultValue float64) float64
	GetBoolValue(key string, defaultValue bool) bool
	GetStringSliceValue(key string, defaultValue []string) []string
	GetIntSliceValue(key string, defaultValue []int) []int
	AddChangeListener(listener storage.ChangeListener)
	RemoveChangeListener(listener storage.ChangeListener)
	GetChangeListeners() *list.List
	UseEventDispatch()
	Close()
}

Client apollo 客户端接口

func Start

func Start() (Client, error)

Start 根据默认文件启动

func StartWithConfig

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

StartWithConfig 根据配置启动

Jump to

Keyboard shortcuts

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