config

package
v0.0.0-...-c058346 Latest Latest
Warning

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

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

README

config

a simple configuration package for Go applications capable of loading configuration data from toml files and/or environment variables. The package is a simple wrapper around the flag.FlagSet package and can be used in pretty much the same way.

Credit

This is an adaptation of go-toml-config. Thanks to the original authors for their work.

Example

With my_app.conf:

country = "USA"

[atlanta]
enabled = true
population = 432427
temperature = 99.6

Or with

export MY_APP_COUNTRY=USA
export MY_APP_ATLANTA_ENABLED=false
export MY_APP_ATLANTA_POPULATION=0
export MY_APP_ATLANTA_TEMPERATURE=0

Use:

import "github.com/drone/config"

var (
  country            = config.String("country", "Unknown")
  atlantaEnabled     = config.Bool("atlanta-enabled", false)
  alantaPopulation   = config.Int("atlanta-population", 0)
  atlantaTemperature = config.Float("atlanta-temperature", 0)
)

func main() {
  config.SetPrefix("MY_APP_")
  config.Parse("/path/to/my_app.conf")
}

Documentation

Index

Constants

Variables

This section is empty.

Functions

func Bool

func Bool(name string, value bool) *bool

Bool defines a bool config variable with a given name and default value.

func BoolVar

func BoolVar(p *bool, name string, value bool)

BoolVar defines a bool config with a given name and default value. The argument p points to a bool variable in which to store the value of the config.

func Duration

func Duration(name string, value time.Duration) *time.Duration

Duration defines a time.Duration config variable with a given name and default value.

func DurationVar

func DurationVar(p *time.Duration, name string, value time.Duration)

DurationVar defines a time.Duration config with a given name and default value. The argument p points to a time.Duration variable in which to store the value of the config.

func Float64

func Float64(name string, value float64) *float64

Float64 defines a float64 config variable with a given name and default value.

func Float64Var

func Float64Var(p *float64, name string, value float64)

Float64Var defines a float64 config with a given name and default value. The argument p points to a float64 variable in which to store the value of the config.

func Int

func Int(name string, value int) *int

Int defines a int config variable with a given name and default value.

func Int64

func Int64(name string, value int64) *int64

Int64 defines a int64 config variable with a given name and default value.

func Int64Var

func Int64Var(p *int64, name string, value int64)

Int64Var defines a int64 config with a given name and default value. The argument p points to a int64 variable in which to store the value of the config.

func IntVar

func IntVar(p *int, name string, value int)

IntVar defines a int config with a given name and default value. The argument p points to a int variable in which to store the value of the config.

func Parse

func Parse(path string) error

Parse takes a path to a TOML file and loads it into the global ConfigSet. This must be called after all config flags have been defined but before the flags are accessed by the program.

func ParseBytes

func ParseBytes(path string) error

ParseBytes takes a TOML file in byte array format and loads it into the global ConfigSet. This must be called after all config flags have been defined but before the flags are accessed by the program.

func SetPrefix

func SetPrefix(prefix string)

SetPrefix sets the applicatin prefix to use when filtering environment variables. If prefix is empty, all environment variables are ignored.

func String

func String(name string, value string) *string

String defines a string config variable with a given name and default value.

func StringVar

func StringVar(p *string, name string, value string)

StringVar defines a string config with a given name and default value. The argument p points to a string variable in which to store the value of the config.

func Uint

func Uint(name string, value uint) *uint

Uint defines a uint config variable with a given name and default value.

func Uint64

func Uint64(name string, value uint64) *uint64

Uint64 defines a uint64 config variable with a given name and default value.

func Uint64Var

func Uint64Var(p *uint64, name string, value uint64)

Uint64Var defines a uint64 config with a given name and default value. The argument p points to a uint64 variable in which to store the value of the config.

func UintVar

func UintVar(p *uint, name string, value uint)

UintVar defines a uint config with a given name and default value. The argument p points to a uint variable in which to store the value of the config.

func Var

func Var(value flag.Value, name string)

Var defines a flag with the specified name and usage string. The type and value of the flag are represented by the first argument, of type Value, which typically holds a user-defined implementation of Value.

Types

type ConfigSet

type ConfigSet struct {
	*flag.FlagSet
	// contains filtered or unexported fields
}

func NewConfigSet

func NewConfigSet(name string, errorHandling flag.ErrorHandling) *ConfigSet

NewConfigSet returns a new ConfigSet with the given name and error handling policy. The three valid error handling policies are: flag.ContinueOnError, flag.ExitOnError, and flag.PanicOnError.

func (*ConfigSet) Bool

func (c *ConfigSet) Bool(name string, value bool) *bool

Bool defines a bool config variable with a given name and default value for a ConfigSet.

func (*ConfigSet) BoolVar

func (c *ConfigSet) BoolVar(p *bool, name string, value bool)

BoolVar defines a bool config with a given name and default value for a ConfigSet. The argument p points to a bool variable in which to store the value of the config.

func (*ConfigSet) Duration

func (c *ConfigSet) Duration(name string, value time.Duration) *time.Duration

Duration defines a time.Duration config variable with a given name and default value.

func (*ConfigSet) DurationVar

func (c *ConfigSet) DurationVar(p *time.Duration, name string, value time.Duration)

DurationVar defines a time.Duration config with a given name and default value for a ConfigSet. The argument p points to a time.Duration variable in which to store the value of the config.

func (*ConfigSet) Float64

func (c *ConfigSet) Float64(name string, value float64) *float64

Float64 defines a float64 config variable with a given name and default value for a ConfigSet.

func (*ConfigSet) Float64Var

func (c *ConfigSet) Float64Var(p *float64, name string, value float64)

Float64Var defines a float64 config with a given name and default value for a ConfigSet. The argument p points to a float64 variable in which to store the value of the config.

func (*ConfigSet) Int

func (c *ConfigSet) Int(name string, value int) *int

Int defines a int config variable with a given name and default value for a ConfigSet.

func (*ConfigSet) Int64

func (c *ConfigSet) Int64(name string, value int64) *int64

Int64 defines a int64 config variable with a given name and default value for a ConfigSet.

func (*ConfigSet) Int64Var

func (c *ConfigSet) Int64Var(p *int64, name string, value int64)

Int64Var defines a int64 config with a given name and default value for a ConfigSet. The argument p points to a int64 variable in which to store the value of the config.

func (*ConfigSet) IntVar

func (c *ConfigSet) IntVar(p *int, name string, value int)

IntVar defines a int config with a given name and default value for a ConfigSet. The argument p points to a int variable in which to store the value of the config.

func (*ConfigSet) Parse

func (c *ConfigSet) Parse(path string) error

Parse takes a path to a TOML file and loads it. This must be called after all the config flags in the ConfigSet have been defined but before the flags are accessed by the program.

If the path is empty, no TOML file is loaded. Only environment variables matching the application Prefix will populate the config flags.

func (*ConfigSet) ParseBytes

func (c *ConfigSet) ParseBytes(data []byte) error

ParseBytes takes a TOML file in byte array format and loads it. This must be called after all the config flags in the ConfigSet have been defined but before the flags are accessed by the program.

func (*ConfigSet) SetPrefix

func (c *ConfigSet) SetPrefix(prefix string)

SetPrefix sets the applicatin prefix to use when filtering environment variables. If prefix is empty, all environment variables are ignored.

func (*ConfigSet) String

func (c *ConfigSet) String(name string, value string) *string

String defines a string config variable with a given name and default value for a ConfigSet.

func (*ConfigSet) StringVar

func (c *ConfigSet) StringVar(p *string, name string, value string)

StringVar defines a string config with a given name and default value for a ConfigSet. The argument p points to a string variable in which to store the value of the config.

func (*ConfigSet) Strings

func (c *ConfigSet) Strings(name string) *StringParams

Strings defines a string slice config variable with a given name.

func (*ConfigSet) Uint

func (c *ConfigSet) Uint(name string, value uint) *uint

Uint defines a uint config variable with a given name and default value for a ConfigSet.

func (*ConfigSet) Uint64

func (c *ConfigSet) Uint64(name string, value uint64) *uint64

Uint64 defines a uint64 config variable with a given name and default value for a ConfigSet.

func (*ConfigSet) Uint64Var

func (c *ConfigSet) Uint64Var(p *uint64, name string, value uint64)

Uint64Var defines a uint64 config with a given name and default value for a ConfigSet. The argument p points to a uint64 variable in which to store the value of the config.

func (*ConfigSet) UintVar

func (c *ConfigSet) UintVar(p *uint, name string, value uint)

UintVar defines a uint config with a given name and default value for a ConfigSet. The argument p points to a uint variable in which to store the value of the config.

func (*ConfigSet) Var

func (c *ConfigSet) Var(value flag.Value, name string)

Var defines a flag with the specified name and usage string. The type and value of the flag are represented by the first argument, of type Value, which typically holds a user-defined implementation of Value.

type StringParams

type StringParams []string

func Strings

func Strings(name string) *StringParams

Strings defines a string slice config variable with a given name.

func (*StringParams) Set

func (s *StringParams) Set(value string) error

func (*StringParams) String

func (s *StringParams) String() string

Jump to

Keyboard shortcuts

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