Giter Club home page Giter Club logo

lunar's Introduction

lunar

GoDoc Build Status codecov Release

Probably the most elegant ctrip apollo client in golang. This library has no third-party dependency.

Ctrip Apollo: https://github.com/ctripcorp/apollo

Default settings of lunar:

  • default namespace is application
  • default server is localhost:8080
  • default http client timeout is 90s

Usage

import "github.com/hyperjiang/lunar"

key := "foo"

app := lunar.New("myAppID", lunar.WithServer("localhost:8080"))

// get value of key in default namespace
app.GetValue(key)

// get value of key in namespace ns
app.GetValueInNamespace(key, "ns")

// get all the items in default namespace
app.GetItems()

// get all the items in namespace ns
app.GetItemsInNamespace("ns")

// get the content of ns namespace, if the format of ns is properties then will return json string
app.GetContent("ns")

// it will fetch items from apollo directly without reading local cache
app.GetNamespaceFromApollo("ns")

// watch changes of given namespaces
watchChan, errChan := app.Watch("ns1", "ns2", ...)

for {
	select {
	case n := <-watchChan:
		fmt.Println(n)
	case <-errChan:
		app.Stop() // stop watcher
		return
	}
}

Logging

lunar does not write logs by default, if you want to see logs for debugging, you can replace it with any logger which implements lunar.Logger interface.

lunar also provide a simple logger lunar.Printf which writes to stdout:

app := lunar.New("myAppID", lunar.WithServer("localhost:8080"), lunar.WithLogger(lunar.Printf))

Or you can use UseLogger method:

app.UseLogger(lunar.Printf)

Caching

lunar use memory cache by default, you can replace it with any cache which implements lunar.Cache interface.

lunar also provide a file cache lunar.FileCache which use files for caching:

app := lunar.New("myAppID")

app.UseCache(lunar.NewFileCache("myAppID", "/tmp"))

Enable Access Key

Starting from v1.6.0, apollo supports access key feature, you can use WithAccessKeySecret to set the secret:

app := lunar.New(
	"myAppID",
	lunar.WithServer("localhost:8080"),
	lunar.WithAccessKeySecret("mySecret"),
)

lunar's People

Contributors

hyperjiang avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.