config

package
v0.0.0-...-6048ecc Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2015 License: Apache-2.0 Imports: 7 Imported by: 0

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)
	Set(key string, value []byte) error
	Watch(key string, stop chan bool) <-chan *Response
}

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

func NewConfigManager

func NewConfigManager(client backend.Store, keystore io.Reader) (ConfigManager, error)

func NewConsulConfigManager

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

NewConsulConfigManager returns a new ConfigManager backed by consul. Data will be encrypted.

func NewEtcdConfigManager

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

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

func NewStandardConfigManager

func NewStandardConfigManager(client backend.Store) (ConfigManager, error)

func NewStandardConsulConfigManager

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

NewStandardConsulConfigManager returns a new ConfigManager backed by consul.

func NewStandardEtcdConfigManager

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