lxd: github.com/lxc/lxd/lxd/config Index | Files

package config

import "github.com/lxc/lxd/lxd/config"

Index

Package Files

errors.go map.go safe.go schema.go validators.go

func AvailableExecutable Uses

func AvailableExecutable(value string) error

AvailableExecutable checks that the given value is the name of an executable file, in PATH.

type Error Uses

type Error struct {
    Name   string      // The name of the key this error is associated with.
    Value  interface{} // The value that the key was tried to be set to.
    Reason string      // Human-readable reason of the error.
}

Error generated when trying to set a certain config key to certain value.

func (Error) Error Uses

func (e Error) Error() string

Error implements the error interface.

type ErrorList Uses

type ErrorList []*Error

ErrorList is a list of configuration Errors occurred during Load() or Map.Change().

func (ErrorList) Error Uses

func (l ErrorList) Error() string

ErrorList implements the error interface.

func (ErrorList) Len Uses

func (l ErrorList) Len() int

ErrorList implements the sort Interface.

func (ErrorList) Less Uses

func (l ErrorList) Less(i, j int) bool

func (ErrorList) Swap Uses

func (l ErrorList) Swap(i, j int)

type Key Uses

type Key struct {
    Type       Type   // Type of the value. It defaults to String.
    Default    string // If the key is not set in a Map, use this value instead.
    Hidden     bool   // Hide this key when dumping the object.
    Deprecated string // Optional message to set if this config value is deprecated.

    // Optional function used to validate the values. It's called by Map
    // all the times the value associated with this Key is going to be
    // changed.
    Validator func(string) error

    // Optional function to manipulate a value before it's actually saved
    // in a Map. It's called only by Map.Change(), and not by Load() since
    // values passed to Load() are supposed to have been previously
    // processed.
    Setter func(string) (string, error)
}

Key defines the type of the value of a particular config key, along with other knobs such as default, validator, etc.

type Map Uses

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

Map is a structured map of config keys to config values.

Each legal key is declared in a config Schema using a Key object.

func Load Uses

func Load(schema Schema, values map[string]string) (Map, error)

Load creates a new configuration Map with the given schema and initial values. It is meant to be called with a set of initial values that were set at a previous time and persisted to some storage like a database.

If one or more keys fail to be loaded, return an ErrorList describing what went wrong. Non-failing keys are still loaded in the returned Map.

func SafeLoad Uses

func SafeLoad(schema Schema, values map[string]string) (Map, error)

SafeLoad is a wrapper around Load() that does not error when invalid keys are found, and just logs warnings instead. Other kinds of errors are still returned.

func (*Map) Change Uses

func (m *Map) Change(changes map[string]interface{}) (map[string]string, error)

Change the values of this configuration Map.

Return a map of key/value pairs that were actually changed. If some keys fail to apply, details are included in the returned ErrorList.

func (*Map) Dump Uses

func (m *Map) Dump() map[string]interface{}

Dump the current configuration held by this Map.

Keys that match their default value will not be included in the dump. Also, if a Key has its Hidden attribute set to true, it will be rendered as "true", for obfuscating the actual value.

func (*Map) GetBool Uses

func (m *Map) GetBool(name string) bool

GetBool returns the value of the given key, which must be of type Bool.

func (*Map) GetInt64 Uses

func (m *Map) GetInt64(name string) int64

GetInt64 returns the value of the given key, which must be of type Int64.

func (*Map) GetRaw Uses

func (m *Map) GetRaw(name string) string

GetRaw returns the value of the given key, which must be of type String.

func (*Map) GetString Uses

func (m *Map) GetString(name string) string

GetString returns the value of the given key, which must be of type String.

type Schema Uses

type Schema map[string]Key

Schema defines the available keys of a config Map, along with the types and options for their values, expressed using Key objects.

func (Schema) Defaults Uses

func (s Schema) Defaults() map[string]interface{}

Defaults returns a map of all key names in the schema along with their default values.

func (Schema) Keys Uses

func (s Schema) Keys() []string

Keys returns all keys defined in the schema

type Type Uses

type Type int

Type is a numeric code indetifying a node value type.

const (
    String Type = iota
    Bool
    Int64
)

Possible Value types.

Package config imports 9 packages (graph) and is imported by 19 packages. Updated 2018-03-14. Refresh now. Tools for package owners.