goconfigure

package module
v0.0.0-...-117d3a6 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2014 License: MIT Imports: 7 Imported by: 0

README

Deprecated user Viper

GoDoc

goconfigure - Go Library to get configuration from different sources

Introduction

Golang configuration parser via the following ways:

  • ENV
  • etcd
  • JSON
  • YAML
  • flags
  • ZooKeeper
  • Consul
Example
etcdClient := etcd.NewClient([]string{"http://127.0.0.1:4001"})
config := goconfigure.Config{
    Etcd: goconfigure.Etcd{
        Client:    etcdClient,
        Namespace: "goconfigure",
    },
}
config.Add("database_url",
    "Use etcd for configuration.",
    "user=ayerra dbname=goconfigure_example sslmode=disable",
    "GOCONFIGURE_DATABASE_URL",
    "database_url")
config.SetParser(goconfigure.EnvParser)

dbUrl, err := config.Get("database_url")

To get the value from Etcd change the parser to EtcdParser. The key that is searched for etcd is /goconfigure/database_url. That is it takes the from /:namespace/:key.

All values are returned as string.

Documentation

Overview

Read json configuration without goconfigure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadJsonConfig

func ReadJsonConfig(fileRead []byte, o *interface{}) error

Read json to an object from a stream of bytes.

func ReadJsonConfigFromFile

func ReadJsonConfigFromFile(fileName string, o *interface{}) error

Read json to an object from a filename.

Types

type Config

type Config struct {
	Etcd      Etcd
	ParseType ParseType
	// contains filtered or unexported fields
}

func (*Config) Add

func (c *Config) Add(name, desc, defaultValue, envKey, etcdKey string)

func (*Config) Get

func (c *Config) Get(key string) (string, error)

func (*Config) SetParser

func (c *Config) SetParser(parseType ParseType)

type Etcd

type Etcd struct {
	Client    *etcd.Client
	Namespace string
}

type Key

type Key struct {
	Description  string
	DefaultValue string
	EnvKey       string
	EtcdKey      string
}

type ParseType

type ParseType int
const (
	EnvParser ParseType = iota
	EtcdParser
)

Jump to

Keyboard shortcuts

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