etc

package
v4.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2016 License: BSD-3-Clause Imports: 10 Imported by: 5

Documentation

Overview

The Tideland Go Library etc configuration package provides the reading, parsing, and accessing of configuration data. Different readers can be passed as sources for the SML formatted input.

Index

Constants

View Source
const (
	ErrIllegalSourceFormat = iota + 1
	ErrIllegalConfigSource
	ErrCannotReadFile
	ErrInvalidPath
	ErrCannotApply
)

Variables

This section is empty.

Functions

func IsInvalidPathError

func IsInvalidPathError(err error) bool

IsInvalidPathError checks if a path cannot be found.

func PackageVersion

func PackageVersion() version.Version

PackageVersion returns the version of the version package.

Types

type Etc

type Etc interface {
	fmt.Stringer

	// ValueAsString retrieves the string value at a given path. If it
	// doesn't exist the default value dv is returned.
	ValueAsString(path, dv string) string

	// ValueAsBool retrieves the bool value at a given path. If it
	// doesn't exist the default value dv is returned.
	ValueAsBool(path string, dv bool) bool

	// ValueAsInt retrieves the int value at a given path. If it
	// doesn't exist the default value dv is returned.
	ValueAsInt(path string, dv int) int

	// ValueAsFloat64 retrieves the float64 value at a given path. If it
	// doesn't exist the default value dv is returned.
	ValueAsFloat64(path string, dv float64) float64

	// ValueAsTime retrieves the string value at a given path and
	// interprets it as time with the passed format. If it
	// doesn't exist the default value dv is returned.
	ValueAsTime(path, layout string, dv time.Time) time.Time

	// ValueAsDuration retrieves the duration value at a given path.
	// If it doesn't exist the default value dv is returned.
	ValueAsDuration(path string, dv time.Duration) time.Duration

	// Apply creates a new configuration by adding of overwriting
	// the passed values. The keys of the map have to be slash
	// separated configuration paths without the leading "etc".
	Apply(kvs map[string]string) (Etc, error)
}

Etc contains the read etc configuration and provides access to it. The root node "etc" is automatically preceded to the path. The node name have to consist out of 'a' to 'z', '0' to '9', and '-'. The nodes of a path are separated by '/'.

func Read

func Read(source io.Reader) (Etc, error)

Read reads the SML source of the configuration from a reader, parses it, and returns the etc instance.

func ReadFile

func ReadFile(filename string) (Etc, error)

ReadFile reads the SML source of a configuration file, parses it, and returns the etc instance.

func ReadString

func ReadString(source string) (Etc, error)

ReadString reads the SML source of the configuration from a string, parses it, and returns the etc instance.

Jump to

Keyboard shortcuts

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