gofig

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2015 License: Apache-2.0 Imports: 16 Imported by: 724

README

Gofig Build Status Go Report Card Coverage Status GoDoc

Gofig simplifies external, runtime configuration of go programs.

Documentation

Overview

Package gofig simplifies external, runtime configuration of go programs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(r *Registration)

Register registers a new configuration with the config package.

func SetGlobalConfigPath

func SetGlobalConfigPath(path string)

SetGlobalConfigPath sets the path of the directory from which the global configuration file is read.

func SetUserConfigPath

func SetUserConfigPath(path string)

SetUserConfigPath sets the path of the directory from which the user configuration file is read.

Types

type Config

type Config interface {

	// Parent gets the configuration's parent (if set).
	Parent() Config

	// Scope returns a scoped view of the configuration. The specified scope
	// string will be used to prefix all property retrievals via the Get
	// and Set functions. Please note that the other functions will still
	// operate as they would for the non-scoped configuration instance. This
	// includes the AllSettings and AllKeys functions as well; they are *not*
	// scoped.
	Scope(scope string) Config

	// FlagSets gets the config's flag sets.
	FlagSets() map[string]*flag.FlagSet

	// GetString returns the value associated with the key as a string
	GetString(k string) string

	// GetBool returns the value associated with the key as a bool
	GetBool(k string) bool

	// GetStringSlice returns the value associated with the key as a string
	// slice.
	GetStringSlice(k string) []string

	// GetInt returns the value associated with the key as an int
	GetInt(k string) int

	// Get returns the value associated with the key
	Get(k string) interface{}

	// Set sets an override value
	Set(k string, v interface{})

	// IsSet returns a flag indicating whether or not a key is set.
	IsSet(k string) bool

	// Copy creates a copy of this Config instance
	Copy() (Config, error)

	// ToJSON exports this Config instance to a JSON string
	ToJSON() (string, error)

	// ToJSONCompact exports this Config instance to a compact JSON string
	ToJSONCompact() (string, error)

	// MarshalJSON implements the encoding/json.Marshaller interface. It allows
	// this type to provide its own marshalling routine.
	MarshalJSON() ([]byte, error)

	// ReadConfig reads a configuration stream into the current config instance
	ReadConfig(in io.Reader) error

	// ReadConfigFile reads a configuration files into the current config
	// instance
	ReadConfigFile(filePath string) error

	// EnvVars returns an array of the initialized configuration keys as
	// key=value strings where the key is configuration key's environment
	// variable key and the value is the current value for that key.
	EnvVars() []string

	// AllKeys gets a list of all the keys present in this configuration.
	AllKeys() []string

	// AllSettings gets a map of this configuration's settings.
	AllSettings() map[string]interface{}
}

Config is the interface that enables retrieving configuration information.

func FromJSON

func FromJSON(from string) (Config, error)

FromJSON initializes a new Config instance from a JSON string

func New

func New() Config

New initializes a new instance of a Config struct

func NewConfig

func NewConfig(
	loadGlobalConfig, loadUserConfig bool,
	configName, configType string) Config

NewConfig initialies a new instance of a Config object with the specified options.

type KeyType

type KeyType int

KeyType is a config registration key type.

const (
	// String is a key with a string value
	String KeyType = iota

	// Int is a key with an integer value
	Int

	// Bool is a key with a boolean value
	Bool
)

type Registration

type Registration struct {
	// contains filtered or unexported fields
}

Registration is used to register configuration information with the gofig package.

func NewRegistration

func NewRegistration(name string) *Registration

NewRegistration creates a new registration with the given name.

func (*Registration) Key

func (r *Registration) Key(
	keyType KeyType,
	short string,
	defVal interface{},
	description string,
	keys ...string)

Key adds a key to the registration.

The first vararg argument is the yaml name of the key, using a '.' as the nested separator. If the second two arguments are omitted they will be generated from the first argument. The second argument is the explicit name of the flag bound to this key. The third argument is the explicit name of the environment variable bound to thie key.

func (*Registration) Yaml

func (r *Registration) Yaml(y string)

Yaml sets the registration's default yaml configuration.

Jump to

Keyboard shortcuts

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