config

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2014 License: MIT Imports: 7 Imported by: 1

README

crypt/config

Usage

Get configuration from a backend
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/xordataexchange/crypt/config"
)

var (
	key           = "/app/config"
	secretKeyring = ".secring.gpg"
)

func main() {
	kr, err := os.Open(secretKeyring)
	if err != nil {
		log.Fatal(err)
	}
	defer kr.Close()
	machines := []string{"http://127.0.0.1:4001"}
	cm, err := config.NewEtcdConfigManager(machines, kr)
	if err != nil {
        log.Fatal(err)
    }
	value, err := cm.Get(key)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s\n", value)
}
Monitor backend for configuration changes
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/xordataexchange/crypt/config"
)

var (
	key           = "/app/config"
	secretKeyring = ".secring.gpg"
)

func main() {
	kr, err := os.Open(secretKeyring)
	if err != nil {
		log.Fatal(err)
	}
	defer kr.Close()
	machines := []string{"http://127.0.0.1:4001"}
	cm, err := config.NewEtcdConfigManager(machines, kr)
	if err != nil {
		log.Fatal(err)
	}
	stop := make(chan bool, 0)
	resp := cm.Watch(key, stop)
	if err != nil {
		log.Fatal(err)
	}
	for {
		select {
		case r := <-resp:
			if r.Error != nil {
				fmt.Println(r.Error.Error())
			}
			fmt.Printf("%s\n", r.Value)
		}
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigManager

type ConfigManager interface {
	Get(key string) ([]byte, error)
	Watch(key string, stop chan bool) <-chan *Response
}

A ConfigManager retrieves and decrypts configuration from a key/value store.

func NewConsulConfigManager

func NewConsulConfigManager(machines []string, keystore io.Reader) (ConfigManager, error)

NewConsulConfigManager returns a new ConfigManager backed by consul.

func NewEtcdConfigManager

func NewEtcdConfigManager(machines []string, keystore io.Reader) (ConfigManager, error)

NewEtcdConfigManager returns a new ConfigManager backed by etcd. Data will be encrypted.

func NewStandardConsulConfigManager added in v0.0.2

func NewStandardConsulConfigManager(machines []string) (ConfigManager, error)

NewStandardConsulConfigManager returns a new ConfigManager backed by consul.

func NewStandardEtcdConfigManager added in v0.0.2

func NewStandardEtcdConfigManager(machines []string) (ConfigManager, error)

NewStandardEtcdConfigManager returns a new ConfigManager backed by etcd.

type Response

type Response struct {
	Value []byte
	Error error
}

Jump to

Keyboard shortcuts

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