agollo

package module
v2.2.1-0...-c38f7dc Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: MIT Imports: 17 Imported by: 0

README

agollo is a golang client for apollo 🚀 CircleCI

Go Report Card codebeat badge Coverage Status golang GoDoc GitHub release

Simple chinese

简体中文

Feature

  • Multiple namespace support
  • Fail tolerant
  • Zero dependency
  • Realtime change notification

Required

go 1.9 or later

Installation

Since we hacked something in upstream repo, just install the agollo via the following command:

    go get -u github.com/Colstuwjx/agollo

Usage

Start use default app.properties config file
    agollo.Start()
Start use given config file path
    agollo.StartWithConfFile(name)
Subscribe to updates
    events := agollo.WatchUpdate()
    changeEvent := <-events
    bytes, _ := json.Marshal(changeEvent)
    fmt.Println("event:", string(bytes))
Get apollo values
    agollo.GetStringValue(Key, defaultValue)
    agollo.GetStringValueWithNameSpace(namespace, key, defaultValue)
Get namespace file contents
    agollo.GetNameSpaceContent(namespace, defaultValue)
Get all keys
    agollo.GetAllKeys(namespace)
Subscribe to new namespaces
    agollo.SubscribeToNamespaces("newNamespace1", "newNamespace2")

License

agollo is released under MIT license

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAllKeys

func GetAllKeys(namespace string) []string

GetAllKeys return all config keys in given namespace

func GetNameSpaceContent

func GetNameSpaceContent(namespace, defaultValue string) string

GetNameSpaceContent get contents of namespace

func GetStringValue

func GetStringValue(key, defaultValue string) string

GetStringValue from default namespace

func GetStringValueWithNameSpace

func GetStringValueWithNameSpace(namespace, key, defaultValue string) string

GetStringValueWithNameSpace get value from given namespace

func Start

func Start() error

Start agollo

func StartWithConf

func StartWithConf(conf *Conf) error

StartWithConf run agollo with Conf

func StartWithConfFile

func StartWithConfFile(name string) error

StartWithConfFile run agollo with conf file

func Stop

func Stop() error

Stop sync config

func SubscribeToNamespaces

func SubscribeToNamespaces(namespaces ...string) error

SubscribeToNamespaces fetch namespace config to local and subscribe to updates

func WatchUpdate

func WatchUpdate() <-chan *ChangeEvent

WatchUpdate get all updates

Types

type Change

type Change struct {
	OldValue   string
	NewValue   string
	ChangeType ChangeType
}

Change represent a single key change

type ChangeEvent

type ChangeEvent struct {
	Namespace string
	Changes   map[string]*Change
}

ChangeEvent change event

type ChangeType

type ChangeType int

ChangeType for a key

const (
	// ADD a new value
	ADD ChangeType = iota
	// MODIFY a old value
	MODIFY
	// DELETE ...
	DELETE
)

func (ChangeType) String

func (c ChangeType) String() string

type Client

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

Client for apollo

func NewClient

func NewClient(conf *Conf) *Client

NewClient create client from conf

func (*Client) Download

func (c *Client) Download(namespace, filepath string) error

Download dump namespace content cache to specified file path

func (*Client) GetAllKeys

func (c *Client) GetAllKeys(namespace string) []string

GetAllKeys return all config keys in given namespace

func (*Client) GetNameSpaceContent

func (c *Client) GetNameSpaceContent(namespace, defaultValue string) string

GetNameSpaceContent get contents of namespace

func (*Client) GetStringValue

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

GetStringValue from default namespace

func (*Client) GetStringValueWithNameSpace

func (c *Client) GetStringValueWithNameSpace(namespace, key, defaultValue string) string

GetStringValueWithNameSpace get value from given namespace

func (*Client) Start

func (c *Client) Start() error

Start sync config

func (*Client) Stop

func (c *Client) Stop() error

Stop sync config

func (*Client) SubscribeToNamespaces

func (c *Client) SubscribeToNamespaces(namespaces ...string) error

SubscribeToNamespaces fetch namespace config to local and subscribe to updates

func (*Client) WatchUpdate

func (c *Client) WatchUpdate() <-chan *ChangeEvent

WatchUpdate get all updates

type Conf

type Conf struct {
	AppID          string   `json:"appId,omitempty"`
	Cluster        string   `json:"cluster,omitempty"`
	NameSpaceNames []string `json:"namespaceNames,omitempty"`
	CacheDir       string   `json:"cacheDir,omitempty"`
	IP             string   `json:"ip,omitempty"`
}

Conf ...

func NewConf

func NewConf(name string) (*Conf, error)

NewConf create Conf from file

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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