echo

package module
v0.0.0-...-6236c02 Latest Latest
Warning

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

Go to latest
Published: May 31, 2018 License: MIT Imports: 5 Imported by: 0

README

echoGoDoc

Echo is a configuration manager based etcd .

Main functions
  • Read paramters under special directory from etcd easily
  • Automatic update configuration data in memory, while add, update or delete value under special etcd directory in etcd
Getting started
# run etcd on docker
docker pull etcd
docker run -d --name echo_etcd -p 2379:2379 etcd  

# set some example k/v paramters
docker exec -it echo_etcd /bin/sh

ETCDCTL_API=3 etcdctl put "hi/echo/name" kim
ETCDCTL_API=3 etcdctl put "hi/echo/age" 18

# download echo lib
$ go get -u github.com/Wang-Kai/echo

go test -v -run=GetConf
package misc

import (
   "log"

   "github.com/Wang-Kai/echo"
)

var AppConf echo.Config

const (
   etcdURI        = "http://127.0.0.1:2379"
   configParamDir = "my_config/"
)

// load config paramters
func init() {
   echoAgent, err := echo.New(etcdURI)
   if err != nil {
   	log.Fatal(err)
   }

   config, err := echoAgent.GetConf(configParamDir)
   if err != nil {
   	log.Fatal(err)
   }
   
   // export global configuration
   AppConf = config

   // use your config any where
   //  ...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config map[string]string

Config a k/v string map to save setting info

func (Config) Get

func (c Config) Get(k string) (val string, exist bool)

Get return value in config for `k`

type Echo

type Echo struct {
	Configs map[string]Config
}

Echo the instance of echo lib

func New

func New(endponters ...string) (*Echo, error)

New make link to etcd server, and create Echo instance

@endponters: the url of etcd server

func (*Echo) GetConf

func (e *Echo) GetConf(etcdDir string) (Config, error)

GetConf get all k/v from etcd prefix with special etcdDir, and save k/v in map

@etcdDir: the dir of config keys prefix with

Jump to

Keyboard shortcuts

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