config

package
v2.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2019 License: MIT Imports: 8 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)
	List(key string) (KVPairs, 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 NewEtcdv3ConfigManager

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

NewEtcdv3ConfigManager returns a new ConfigManager backed by etcdv3. Data will be encrypted.

func NewStandardConfigManager

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

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.

func NewStandardEtcdv3ConfigManager

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

NewStandardEtcdv3ConfigManager returns a new ConfigManager backed by etcd.

type KVPair

type KVPair struct {
	backend.KVPair
}

type KVPairs

type KVPairs []*KVPair

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