config

package module
v0.0.0-...-355b49c Latest Latest
Warning

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

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

README

config Build Status GoDoc

This Go package adds configuration file management.

Noteworthy features:

  • simple file syntax based on sections
  • extraction of Duration and []byte
  • variable substitution
  • overwriting values by command-line args and environment properties
  • named sub-sections
  • merging multiple files

Install

go get github.com/stephanos/config

Documentation

godoc.org

Credit

The package creates functionality on top of https://bitbucket.org/gosimple/conf/

License

MIT (see LICENSE).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

Config represents configuration settings.

func New

func New(prefix string, sources ...string) (*Config, error)

New creates a Config from config files; or returns an error if any of the files couldn't be opened/parsed.

The passed-in prefix is used to filter environment variables meant to overwrite config values of the files.

func (*Config) HasSection

func (conf *Config) HasSection(name string) (match bool)

HasSection tests whether a section exists.

func (*Config) SectionMust

func (conf *Config) SectionMust(name string, id ...string) *Section

SectionMust returns the section from the config that matches the passed-in name; or panics if it does not exist. If there are multiple sections with the same name the optional passed-in id decides which to use.

func (*Config) Sections

func (conf *Config) Sections(name string) map[string]*Section

Sections returns a map of all sections with the passed-in name. The key of the returned map equals the section's ID.

type Section

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

Section represents a named group of configuration options.

func (*Section) Add

func (sect *Section) Add(option string, value string) bool

Add adds a new option and value to the configuration. It returns true if the option and value were inserted, and false if the value was overwritten.

func (*Section) Bool

func (sect *Section) Bool(option string) (bool, error)

Bool returns the boolean value of the option; or an error if the conversion failed / the value didn't exist.

func (*Section) Bytes

func (sect *Section) Bytes(option string) ([]byte, error)

Bytes returns the raw byte array of the option; or an error if the conversion failed / the value didn't exist.

func (*Section) Duration

func (sect *Section) Duration(option string) (time.Duration, error)

Duration returns the time duration value of the option; or an error if the conversion failed / the value didn't exist.

func (*Section) Float

func (sect *Section) Float(option string) (float64, error)

Float returns the decimal value of the option; or an error if the conversion failed / the value didn't exist.

func (*Section) ID

func (sect *Section) ID() string

ID returns the unique identifier of the section ("default" by default).

func (*Section) Int

func (sect *Section) Int(option string) (int, error)

Int returns the numeric value of the option; or an error if the conversion failed / the value didn't exist.

func (*Section) String

func (sect *Section) String(option string) (string, error)

String returns the text value of the option; or an error if it does not exist.

Jump to

Keyboard shortcuts

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