hydrator

package module
v0.0.0-...-880be8e Latest Latest
Warning

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

Go to latest
Published: May 1, 2016 License: MIT Imports: 8 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultSeparator    = "."
	Debug               = false
	DebugEnvironmentVar = "ETCD_HYDRATOR_DEBUG"
)

Functions

This section is empty.

Types

type Hydrator

type Hydrator struct {
	Folder    string
	Separator string
	// contains filtered or unexported fields
}

func NewHydrator

func NewHydrator(client etcd.Client) *Hydrator

func (*Hydrator) Hydrate

func (h *Hydrator) Hydrate(variable interface{})

Jump to

Keyboard shortcuts

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