config

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2020 License: GPL-3.0 Imports: 11 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// StateDirectory contains the path to the directory that
	// should be used to store any data that should be
	// preserved between sessions.
	//
	// Value of this variable must not change after initialization
	// in cmd/maddy/main.go.
	StateDirectory string

	// RuntimeDirectory contains the path to the directory that
	// should be used to store any temporary data.
	//
	// It should be preferred over os.TempDir, which is
	// global and world-readable on most systems, while
	// RuntimeDirectory can be dedicated for maddy.
	//
	// Value of this variable must not change after initialization
	// in cmd/maddy/main.go.
	RuntimeDirectory string

	// LibexecDirectory contains the path to the directory
	// where helper binaries should be searched.
	//
	// Value of this variable must not change after initialization
	// in cmd/maddy/main.go.
	LibexecDirectory string
)

Functions

func NodeErr

func NodeErr(node Node, f string, args ...interface{}) error

func ParseDataSize

func ParseDataSize(s string) (int, error)

Types

type Endpoint

type Endpoint struct {
	Original, Scheme, Host, Port, Path string
}

Endpoint represents a site address. It contains the original input value, and the component parts of an address. The component parts may be updated to the correct values as setup proceeds, but the original value should never be changed.

func ParseEndpoint

func ParseEndpoint(str string) (Endpoint, error)

ParseEndpoint parses an endpoint string into a structured format with separate scheme, host, port, and path portions, as well as the original input string.

func (Endpoint) Address

func (e Endpoint) Address() string

func (Endpoint) IsTLS

func (e Endpoint) IsTLS() bool

func (Endpoint) Network

func (e Endpoint) Network() string

func (Endpoint) String

func (e Endpoint) String() string

String returns a human-friendly print of the address.

type Map

type Map struct {

	// All values saved by Map during processing.
	Values map[string]interface{}

	// Values used by Process as default values if inheritGlobal is true.
	Globals map[string]interface{}
	// Config block used by Process.
	Block Node
	// contains filtered or unexported fields
}

Map structure implements reflection-based conversion between configuration directives and Go variables.

func NewMap

func NewMap(globals map[string]interface{}, block Node) *Map

func (*Map) AllowUnknown

func (m *Map) AllowUnknown()

AllowUnknown makes config.Map skip unknown configuration directives instead of failing.

func (*Map) Bool

func (m *Map) Bool(name string, inheritGlobal, defaultVal bool, store *bool)

Bool maps presence of some configuration directive to a boolean variable. Additionally, 'name yes' and 'name no' are mapped to true and false correspondingly.

I.e. if directive 'io_debug' exists in processed configuration block or in the global configuration (if inheritGlobal is true) then Process will store true in target variable.

func (*Map) Callback

func (m *Map) Callback(name string, mapper func(*Map, Node) error)

Callback creates mapping that will call mapper() function for each directive with the specified name. No further processing is done.

Directives with the specified name will not be returned by Process if AllowUnknown is used.

It is intended to permit multiple independent values of directive with implementation-defined handling.

func (*Map) Custom

func (m *Map) Custom(name string, inheritGlobal, required bool, defaultVal func() (interface{}, error), mapper func(*Map, Node) (interface{}, error), store interface{})

Custom maps configuration directive with the specified name to variable referenced by 'store' pointer.

If inheritGlobal is true - Map will try to use a value from globalCfg if none is set in a processed configuration block.

If required is true - Map will fail if no value is set in the configuration, both global (if inheritGlobal is true) and in the processed block.

defaultVal is a factory function that should return the default value for the variable. It will be used if no value is set in the config. It can be nil if required is true. Note that if inheritGlobal is true, defaultVal of the global directive will be used instead.

mapper is a function that should convert configuration directive arguments into variable value. Both functions may fail with errors, configuration processing will stop immediately then. Note: mapper function should not modify passed values.

store is where the value returned by mapper should be stored. Can be nil (value will be saved only in Map.Values).

func (*Map) DataSize

func (m *Map) DataSize(name string, inheritGlobal, required bool, defaultVal int, store *int)

DataSize maps configuration directive to a int variable, representing data size.

Syntax requires unit suffix to be added to the end of string to specify data unit and allows multiple arguments (they will be added together).

See Map.Custom for description of arguments.

func (*Map) Duration

func (m *Map) Duration(name string, inheritGlobal, required bool, defaultVal time.Duration, store *time.Duration)

Duration maps configuration directive to a time.Duration variable.

Directive must be in form 'name duration' where duration is any string accepted by time.ParseDuration. As an additional requirement, result of time.ParseDuration must not be negative.

Note that for convenience, if directive does have multiple arguments, they will be joined without separators. E.g. 'name 1h 2m' will become 'name 1h2m' and so '1h2m' will be passed to time.ParseDuration.

See Map.Custom for description of arguments.

func (*Map) Enum

func (m *Map) Enum(name string, inheritGlobal, required bool, allowed []string, defaultVal string, store *string)

Enum maps a configuration directive to a string variable.

Directive must be in form 'name string' where string should be from *allowed* slice. That string argument will be stored in store variable.

See Map.Custom for description of inheritGlobal and required.

func (*Map) EnumList

func (m *Map) EnumList(name string, inheritGlobal, required bool, allowed []string, defaultVal []string, store *[]string)

EnumList maps a configuration directive to a []string variable.

Directive must be in form 'name string1 string2' where each string should be from *allowed* slice. At least one argument should be present.

See Map.Custom for description of inheritGlobal and required.

func (*Map) Float

func (m *Map) Float(name string, inheritGlobal, required bool, defaultVal float64, store *float64)

Float maps configuration directive with the specified name to variable referenced by 'store' pointer.

Configuration directive must be in form 'name 123.55'.

See Custom function for details about inheritGlobal, required and defaultVal.

func (*Map) Int

func (m *Map) Int(name string, inheritGlobal, required bool, defaultVal int, store *int)

Int maps configuration directive with the specified name to variable referenced by 'store' pointer.

Configuration directive must be in form 'name 123'.

See Custom function for details about inheritGlobal, required and defaultVal.

func (*Map) Int32

func (m *Map) Int32(name string, inheritGlobal, required bool, defaultVal int32, store *int32)

Int32 maps configuration directive with the specified name to variable referenced by 'store' pointer.

Configuration directive must be in form 'name 123'.

See Custom function for details about inheritGlobal, required and defaultVal.

func (*Map) Int64

func (m *Map) Int64(name string, inheritGlobal, required bool, defaultVal int64, store *int64)

Int64 maps configuration directive with the specified name to variable referenced by 'store' pointer.

Configuration directive must be in form 'name 123'.

See Custom function for details about inheritGlobal, required and defaultVal.

func (*Map) Process

func (m *Map) Process() (unknown []Node, err error)

Process maps variables from global configuration and block passed in NewMap.

If Map instance was not created using NewMap - Process panics.

func (*Map) ProcessWith

func (m *Map) ProcessWith(globalCfg map[string]interface{}, block Node) (unknown []Node, err error)

Process maps variables from global configuration and block passed in arguments.

func (*Map) String

func (m *Map) String(name string, inheritGlobal, required bool, defaultVal string, store *string)

String maps configuration directive with the specified name to variable referenced by 'store' pointer.

Configuration directive must be in form 'name arbitrary_string'.

See Custom function for details about inheritGlobal, required and defaultVal.

func (*Map) StringList

func (m *Map) StringList(name string, inheritGlobal, required bool, defaultVal []string, store *[]string)

StringList maps configuration directive with the specified name to variable referenced by 'store' pointer.

Configuration directive must be in form 'name arbitrary_string arbitrary_string ...' Where at least one argument must be present.

See Custom function for details about inheritGlobal, required and defaultVal.

func (*Map) UInt

func (m *Map) UInt(name string, inheritGlobal, required bool, defaultVal uint, store *uint)

UInt maps configuration directive with the specified name to variable referenced by 'store' pointer.

Configuration directive must be in form 'name 123'.

See Custom function for details about inheritGlobal, required and defaultVal.

func (*Map) UInt32

func (m *Map) UInt32(name string, inheritGlobal, required bool, defaultVal uint32, store *uint32)

UInt32 maps configuration directive with the specified name to variable referenced by 'store' pointer.

Configuration directive must be in form 'name 123'.

See Custom function for details about inheritGlobal, required and defaultVal.

func (*Map) UInt64

func (m *Map) UInt64(name string, inheritGlobal, required bool, defaultVal uint64, store *uint64)

UInt64 maps configuration directive with the specified name to variable referenced by 'store' pointer.

Configuration directive must be in form 'name 123'.

See Custom function for details about inheritGlobal, required and defaultVal.

type Node

type Node = parser.Node

Directories

Path Synopsis
Package modconfig provides matchers for config.Map that query modules registry and parse inline module definitions.
Package modconfig provides matchers for config.Map that query modules registry and parse inline module definitions.

Jump to

Keyboard shortcuts

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