bconf

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitFromBconf

func InitFromBconf(dst BconfAdder, src Bconf)

Initialize the BconfAdder from a Bconf interface.

func KeyCompare

func KeyCompare(a, b string) int

Compares the two bconf keys with the bconf sort order.

func ReadFile

func ReadFile(bconf BconfAdder, path string, allowEnv bool) error

Reads a bconf file and adds the data to bconf. If allowEnv is true, os.ExpandEnv is called on the values. This is similar to InitFromFile except it doesn't use C code and InitFromFile handles environment variables slightly different.

Lines are on the form

keypath=value

where keypath is a . delimated string and value is any string. Whitespace at the start and end of lines are trimmed. You can also use a include directive which is a line on the form

include path

That path will then also be read if it exists. It's non-fatal if it doesn't. The path is relative to the current file being read.

Lines starting with # are considered comments.

Types

type AddError

type AddError struct {
	Key   interface{}
	Value string
}

Error returned by Add and Addv, indicating there was a tree structure conflict. Key is either a string or a slice of strings, value is always a string.

func (*AddError) Error

func (e *AddError) Error() string

type Bconf

type Bconf interface {
	Get(k ...string) Bconf
	Valid() bool
	Leaf() bool
	String(def string) string
	Int(def int) int
	Bool(def bool) bool
	Slice() []Bconf
	ToMap() map[string]interface{}
	Length() int
	Key() string
}

The basic bconf interface.

type BconfAdder

type BconfAdder interface {
	// Add data to a bconf node
	//
	// The only possible error is an AddError, Key will either be a
	// string or an []string.
	//
	// You can use this function on sub nodes, not only the root,
	// but be sure the node exists by creating at least one leaf value
	// first.
	//
	// Example: err := b.Add("foo.bar", id, "name")("baz")
	Add(k ...string) func(v string) error

	// Add data to a bconf node, using a slice.
	// Note: . (dots) are NOT special in this function call, if passed the node
	// key created will contain the dot, and can't be retrieved using Get, only
	// Slice and ToMap.
	Addv(kv []string, v string) error
}

Functions used to add data to bconf. Implemented by Node and BconfNode.

type Leaf

type Leaf struct {
	KeyName string
	Value   string
}

A leaf bconf node, with key and string value

func (*Leaf) Bool

func (leaf *Leaf) Bool(def bool) bool

func (*Leaf) Get

func (leaf *Leaf) Get(k ...string) Bconf

func (*Leaf) Int

func (leaf *Leaf) Int(def int) int

func (*Leaf) Key

func (leaf *Leaf) Key() string

func (*Leaf) Leaf

func (leaf *Leaf) Leaf() bool

func (*Leaf) Length

func (leaf *Leaf) Length() int

func (*Leaf) Slice

func (leaf *Leaf) Slice() []Bconf

func (*Leaf) String

func (leaf *Leaf) String(def string) string

func (*Leaf) ToMap

func (leaf *Leaf) ToMap() map[string]interface{}

func (*Leaf) Valid

func (leaf *Leaf) Valid() bool

type MutBconf

type MutBconf interface {
	Bconf
	BconfAdder
}

Mutable bconf interface you can use to have write access without knowing the underlying type.

type Node

type Node struct {
	KeyName string
	// contains filtered or unexported fields
}

A non-leaf bconf node with key name and slice of subnodes. The subnodes need to be kept in a consistent state and are thus kept private. Use Add or Addv to add data, and Get, Slice or ToMap to read it.

Root nodes use an empty string key, subnodes have it set.

func (*Node) Add

func (node *Node) Add(k ...string) func(v string) error

Add data to a bconf node

The only possible error is an AddError, the Key field will be the key split on dots.

Only leaf nodes can be created, not calling the returned function might create an inconsistent state.

Example: err := b.Add("foo.bar", id, "name")("baz")

func (*Node) Addv

func (node *Node) Addv(kv []string, v string) error

Add data to a bconf node, using a slice.

Note: . (dots) are NOT special in this function call, if passed the node key created will contain the dot, and can't be retrieved using Get, only Slice and ToMap.

func (*Node) Bool

func (node *Node) Bool(def bool) bool

func (*Node) Delete

func (node *Node) Delete(path ...string)

func (*Node) Get

func (node *Node) Get(k ...string) Bconf

func (*Node) Int

func (node *Node) Int(def int) int

func (*Node) Key

func (node *Node) Key() string

func (*Node) Leaf

func (node *Node) Leaf() bool

func (*Node) Length

func (node *Node) Length() int

func (*Node) Search

func (node *Node) Search(step string) (found bool, index int)

func (*Node) Slice

func (node *Node) Slice() []Bconf

func (*Node) String

func (node *Node) String(def string) string

func (*Node) ToMap

func (node *Node) ToMap() map[string]interface{}

Convert to a go map. This will traverse the node recursively and insert all leaves into a map. Values are either strings or map[string]interface{} sub nodes.

func (*Node) Valid

func (node *Node) Valid() bool

type SyntaxError

type SyntaxError struct {
	Line string
}

A line that failed to parse in ReadFile.

func (SyntaxError) Error

func (se SyntaxError) Error() string

Jump to

Keyboard shortcuts

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