contree

package module
v0.0.0-...-e6c8f10 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 10 Imported by: 0

README

Contree

Contree is a Go library to handle configuration powered by tree data structure.

Installation

go get -u github.com/jakofys/contree

Use

Get value
value := conf.Get("path.to.my.value") // string value
Set value

Just set value using path data:

conf.Set("path.to.my.value", "value") // string value
Interpolation

You can have same behavior as fmt.Sprintf except syntax to interpolate making:

conf.Set("path.to.value", "Casanova")
conf.Sprintf("Simply replace data from %path.to.value%") // Output: Simply replace data Casanova

Reference

Author

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec interface {
	Decode([]byte) *NodeConf
	Encode(*NodeConf) []byte
}

type ConfigLoader

type ConfigLoader func() (map[string]interface{}, error)

Decoder must be able to read specific document, and return key/value

func JSONDecoder

func JSONDecoder(r io.Reader) ConfigLoader

func JSONFileDecoder

func JSONFileDecoder(filename string) ConfigLoader

func TOMLDecoder

func TOMLDecoder(r io.Reader) ConfigLoader

func TOMLFileDecoder

func TOMLFileDecoder(filename string) ConfigLoader

func YAMLDecoder

func YAMLDecoder(r io.Reader) ConfigLoader

func YAMLFileDecoder

func YAMLFileDecoder(filename string) ConfigLoader

type Contree

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

func NewContree

func NewContree(name string) *Contree

func (*Contree) Get

func (c *Contree) Get(path string) (string, error)

func (*Contree) Import

func (c *Contree) Import(loaders ...ConfigLoader) error

Import can take multiple Decoder that extract all data, and transform them to a key/value set of data, and set recursivly into the contree object

func (*Contree) Set

func (c *Contree) Set(path string, value string)

func (*Contree) Sprintf

func (c *Contree) Sprintf(str string) string

type NodeConf

type NodeConf struct {
	Name  string
	Value string
	// contains filtered or unexported fields
}

func (*NodeConf) Browse

func (n *NodeConf) Browse(path string) string

func (*NodeConf) GetValue

func (n *NodeConf) GetValue() string

func (*NodeConf) Insert

func (n *NodeConf) Insert(node *NodeConf)

func (*NodeConf) IsNamed

func (n *NodeConf) IsNamed(str string) bool

func (*NodeConf) Merge

func (n *NodeConf) Merge(node *NodeConf, overwrite bool)

func (*NodeConf) SetRecursivly

func (n *NodeConf) SetRecursivly(path string, value string)

Jump to

Keyboard shortcuts

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