agollo

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2020 License: Apache-2.0 Imports: 18 Imported by: 4

README

apollo-client

a client for apollo using go language, forked from agollo.

Usage

You can see examples in examples.

License

The project is licensed under the Apache 2 license. See more from LICENSE and NOTICE.

Reference

Documentation

Index

Constants

View Source
const (
	// default apollo config file
	DEFAULT_CONFFILE = "app.properties"
	// default backup directory
	DEFAULT_BACKUPDIR = "."
	// default backup file suffix
	DEFAULT_BACKUPSUFFIX = ".apollo.json"
	// default cache size
	DEFAULT_CONFIGCACHESIZE = 50 * 1024 * 1024
	// default namespace
	DEFAULT_NAMESPACENAME = "application"
	// default cluster
	DEFAULT_CLUSTER = "default"

	// default notify timeout, see apollo notifications
	DEFAULT_NOTIFYTIMEOUT = 65 * time.Second

	// default connect timeout
	DEFAULT_CONNECTTIMEOUT = 10 * time.Second
	// default retry interval
	DEFAULT_RETRYINTERVAL = 3 * time.Second
)
View Source
const (
	EMPTY = ""
	SEP   = "."
)

exported constants

View Source
const (
	DEFAULT_NOFICATION_ID = -1
)

Variables

View Source
var (
	DEFAULT_REFRESHINTERVAL  = 5 * time.Minute
	DEFAULT_LONGPOLLINTERVAL = 5 * time.Second
)

Functions

func Cleanup

func Cleanup()

func GetConfigByKey

func GetConfigByKey(key string) (string, error)

func GetConfigCacheMap

func GetConfigCacheMap() map[string]string

func GetNamespaceList

func GetNamespaceList() []string

get namespace list being watched

func Init

func Init(opts ...Option) (err error)

func RegChangeEventHandler

func RegChangeEventHandler(in CHandler)

RegChangeEventHandler register a config change handler on agollo

func Start

func Start()

Start starts agollo

func StartContext

func StartContext(ctx context.Context)

StartContext starts agollo

Types

type CHandler

type CHandler func(event *ChangeEvent) error

CHandler calls a handler to process config change event

type ChangeEvent

type ChangeEvent struct {
	Namespace string
	Changes   []*ConfigChange
}

ChangeEvent is event of cofig change

type ConfigChange

type ConfigChange struct {
	Key        string
	OldValue   string
	NewValue   string
	ChangeType ConfigChangeType
}

ConfigChange contains config change info

type ConfigChangeType

type ConfigChangeType int

ConfigChangeType specifies the type of a certain config

const (
	ADDED ConfigChangeType = iota
	MODIFIED
	DELETED
)

Config change types: add, modified, deleted

type ConfigReader

type ConfigReader interface {
	GetStringValue(key string) (string, error)
	GetIntValue(key string) (int, error)
	GetFloatValue(key string) (float64, error)
	GetBoolValue(key string) (bool, error)
	GetBytesValue(key string) ([]byte, error)
}

ConfigReader gets type-specified value

func GetConfigReader

func GetConfigReader(namespaceName string) ConfigReader

GetConfigReader returns a reader that can read config values

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option contains apply method to load options

func IgnoreNameSpace added in v0.3.0

func IgnoreNameSpace() Option

func WithApolloAddr

func WithApolloAddr(s string) Option

set apollo address, for example:

127.0.0.1:8888
https://meta.apollo.com

func WithAppId

func WithAppId(s string) Option

func WithBackupDir

func WithBackupDir(s string) Option

set backup save directory

func WithBackupSuffix

func WithBackupSuffix(s string) Option

set backup file's suffix name

func WithCacheSize

func WithCacheSize(v int) Option

set cache size

func WithClientIp

func WithClientIp(v string) Option

set client ip

func WithCluster

func WithCluster(s string) Option

func WithConfFile

func WithConfFile(s string) Option

set apollo config file

func WithConnectTimeout

func WithConnectTimeout(v time.Duration) Option

set apollo config connect timeout

func WithDefaultVals

func WithDefaultVals(val map[string]interface{}, namespaceName string) Option

set key's default value for example:

   WithDefaultVals(map[string]interface{}{
		"key1": "11",
	  }, "application")
   when call GetStringValue("key1"), if config key1 not found, return 11
  NOTE: default value is bound to type, if call GetIntValue("key1") will return 0
 NOTE: default value's type is in int/string/bool/float64, will panic when use other types

func WithLogFunc

func WithLogFunc(logDebug, logInfo, logError logger.LogFunc) Option

func WithLongPollInterval

func WithLongPollInterval(v time.Duration) Option

set long poll interval

func WithNamespaceName

func WithNamespaceName(s string) Option

set namespace list, use , to separate each namespace

func WithNotifyTimeout

func WithNotifyTimeout(v time.Duration) Option

set apollo notify timeout

func WithQuickInitWithBK

func WithQuickInitWithBK() Option

get config from backup file when call Init function

func WithRefreshInterval

func WithRefreshInterval(v time.Duration) Option

set refresh interval

func WithRetryInterval

func WithRetryInterval(v time.Duration) Option

set retry interval

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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