Documentation ¶
Index ¶
- func InitFromBconf(dst BconfAdder, src Bconf)
- func KeyCompare(a, b string) int
- func ReadFile(bconf BconfAdder, path string, allowEnv bool) error
- type AddError
- type Bconf
- type BconfAdder
- type Leaf
- func (leaf *Leaf) Bool(def bool) bool
- func (leaf *Leaf) Get(k ...string) Bconf
- func (leaf *Leaf) Int(def int) int
- func (leaf *Leaf) Key() string
- func (leaf *Leaf) Leaf() bool
- func (leaf *Leaf) Length() int
- func (leaf *Leaf) Slice() []Bconf
- func (leaf *Leaf) String(def string) string
- func (leaf *Leaf) ToMap() map[string]interface{}
- func (leaf *Leaf) Valid() bool
- type MutBconf
- type Node
- func (node *Node) Add(k ...string) func(v string) error
- func (node *Node) Addv(kv []string, v string) error
- func (node *Node) Bool(def bool) bool
- func (node *Node) Delete(path ...string)
- func (node *Node) Get(k ...string) Bconf
- func (node *Node) Int(def int) int
- func (node *Node) Key() string
- func (node *Node) Leaf() bool
- func (node *Node) Length() int
- func (node *Node) Search(step string) (found bool, index int)
- func (node *Node) Slice() []Bconf
- func (node *Node) String(def string) string
- func (node *Node) ToMap() map[string]interface{}
- func (node *Node) Valid() bool
- type SyntaxError
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 ¶
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.
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 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 ¶
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 ¶
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.
type SyntaxError ¶
type SyntaxError struct {
Line string
}
A line that failed to parse in ReadFile.
func (SyntaxError) Error ¶
func (se SyntaxError) Error() string