config

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: ISC Imports: 7 Imported by: 1

Documentation

Overview

Package config provides types that represent a plugin's configuration.

The types provided in this package are fairly low level and correspond directly to types in collectd:

· "Block" corresponds to "oconfig_item_t".

· "Value" corresponds to "oconfig_value_t".

Blocks contain a Key, and optionally Values and/or children (nested Blocks). In collectd's configuration, these pieces are represented as follows:

<Key "Value">
	Child "child value"
</Key>

In Go, this would be represented as:

Block{
	Key: "Key",
	Values: []Value{String("Value")},
	Children: []Block{
		{
			Key: "Child",
			Values: []Value{String("child value")},
		},
	},
}

The recommended way to work with configurations is to define a data type representing the configuration, then use "Block.Unmarshal" to map the Block representation onto the data type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	Key      string
	Values   []Value
	Children []Block
}

Block represents one configuration block, which may contain other configuration blocks.

func (Block) IsZero added in v0.6.0

func (b Block) IsZero() bool

IsZero returns true if b is the Zero value.

func (*Block) MarshalText

func (b *Block) MarshalText() ([]byte, error)

MarshalText produces a text version of Block. The result is parseable by collectd. Implements the "encoding".TextMarshaler interface.

func (*Block) Merge

func (b *Block) Merge(other Block) error

Merge appends other's Children to b's Children. If Key or Values differ, an error is returned.

func (*Block) Unmarshal

func (b *Block) Unmarshal(v interface{}) error

Unmarshal applies the configuration from a Block to an arbitrary struct.

type Port

type Port int

Port represents a port number in the configuration. When a configuration is converted to Go types using Unmarshal, it implements special conversion rules: If the config option is a numeric value, it is ensured to be in the range [1–65535]. If the config option is a string, it is converted to a port number using "net".LookupPort (using "tcp" as network).

func (*Port) UnmarshalConfig

func (p *Port) UnmarshalConfig(b Block) error

UnmarshalConfig converts b to a port number.

type Unmarshaler

type Unmarshaler interface {
	UnmarshalConfig(Block) error
}

Unmarshaler is the interface implemented by types that can unmarshal a Block representation of themselves.

type Value

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

Value may be either a string, float64 or boolean value. This is the Go equivalent of the C type "oconfig_value_t".

func Bool added in v0.6.0

func Bool(v bool) Value

Bool returns a new bool Value.

func Float64 added in v0.6.0

func Float64(v float64) Value

Float64 returns a new float64 Value.

func String added in v0.6.0

func String(v string) Value

String returns a new string Value.

func Values

func Values(values ...interface{}) []Value

Values allocates and initializes a []Value slice. "string", "float64", and "bool" are mapped directly. "[]byte" is converted to a string. Numeric types (except complex numbers) are converted to float64. All other values are converted to string using the `%v` format.

func (Value) Bool

func (cv Value) Bool() (bool, bool)

Bool returns the value of a bool Value.

func (Value) Float64

func (cv Value) Float64() (float64, bool)

Float64 returns the value of a float64 Value.

func (Value) GoString

func (cv Value) GoString() string

GoString returns a Go statement for creating cv.

func (Value) Interface

func (cv Value) Interface() interface{}

Interface returns the specific value of Value without specifying its type, useful for functions like fmt.Printf which can use variables with unknown types.

func (Value) IsString

func (cv Value) IsString() bool

IsString returns true if cv is a string Value.

func (Value) String

func (cv Value) String() string

String returns Value as a string. Non-string values are formatted according to their default format.

Jump to

Keyboard shortcuts

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