Skip to content

philchia/agollo

Repository files navigation

agollo is a golang client for apollo πŸš€

Go Report Card codebeat badge Coverage Status golang GoDoc GitHub release

v1:goproxy.cn v3:goproxy.cn v4:goproxy.cn

Feature

  • Multiple namespace support
  • Fail tolerant
  • Zero dependency
  • Realtime change notification
  • API to get contents of namespace

Required

go 1.11 or later

Installation

go get -u github.com/philchia/agollo/v4

Usage

Import agollo

import "github.com/philchia/agollo/v4"

In order to use agollo, issue a client or use the built-in default client

to use the default global client

for namespaces with the format of properties, you need to specific the full name

agollo.Start(&agollo.Conf{
    AppID:          "your app id",
    Cluster:        "default",
    NameSpaceNames: []string{"application.properties"},
    MetaAddr:       "your apollo meta addr",
})

or to issue a new client to embedded into your program

apollo := agollo.New(&agollo.Conf{
                            AppID:          "your app id",
                            Cluster:        "default",
                            NameSpaceNames: []string{"application.properties"},
                            MetaAddr:       "your apollo meta addr",
                        })
apollo.Start()

Set config update callback

agollo.OnUpdate(func(event *ChangeEvent) {
    // do your business logic to handle config update
})

Get apollo values

// get values in the application.properties default namespace
val := agollo.GetString(Key)
// or indicate a namespace
other := agollo.GetString(key, agollo.WithNamespace("other namespace"))

Get namespace file contents

to get namespace of with a format of properties, you need to specific the full name of the namespace, e.g. namespace.properties in both options and configs

namespaceContent := agollo.GetContent(agollo.WithNamespace("application.properties"))

Get all keys

allKyes := agollo.GetAllKeys(namespace)

Subscribe to new namespaces

agollo.SubscribeToNamespaces("newNamespace1", "newNamespace2")

License

agollo is released under MIT license