agollo

package module
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2018 License: MIT Imports: 12 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

Required

go 1.9 or later

Installation

    go get -u github.com/philchia/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)

License

agollo is released under MIT lecense

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 added in v1.1.3

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 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) GetAllKeys

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

GetAllKeys return all config keys in given namespace

func (*Client) GetNameSpaceContent added in v1.1.3

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) 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"`
	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