Giter Club home page Giter Club logo

go-etcd-hydrator's Introduction

go-etcd-hydrator Build Status GoDoc

Installation

The recommended way to install go-etcd-hydrator

go get github.com/mcuadros/go-etcd-hydrator

Examples

This is a very basic example reading a couple of keys from the etcd server:

import (
    "fmt"

    "github.com/coreos/go-etcd/etcd"
    "github.com/mcuadros/go-etcd-hydrator"
)

type MyAppConfig struct {
    Rest string //<-- the hydrator will ask to etcd for `rest` key
    MongoDB string `etcd:"mongo.host"` //<--  ask to etcd for `mongo.host` key
}

func NewMyAppConfig() *MyAppConfig {
    example := new(MyAppConfig)

    h := NewHydrator(etcd.NewClient([]string{"http://127.0.0.1:2379"}))
    h.Hydrate(foo)

    return example
}

...
config := NewMyAppConfig()
fmt.Println(config.Rest) //Prints: http://rest.company.com
fmt.Println(config.MongoDB) //Prints: 127.0.0.1:27017

Required keys on the etcd server:

curl -L -X PUT http://127.0.0.1:4001/v2/keys/rest -d value="http://rest.company.com"
curl -L -X PUT http://127.0.0.1:4001/v2/keys/mongo.host -d value="127.0.0.1:27017"

Debug

You can enable the debug mode of this library setting the environment variable ETCD_HYDRATOR_DEBUG with the value true. (in fact any value is valid)

When this variable is set a small log will be printed to the stdout:

Hydrating var: "*hydrator.Example"
Recovered key "testing/string" with value "foo"
Recovered key "testing/integer" with value "42"
...

License

MIT, see LICENSE

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.