Documentation ¶
Overview ¶
`shlike` implements a flexible configuration file format, based on POSIX `/bin/sh` word splitting, quoting, and expansion. See the README.md file (https://github.com/3ofcoins/shlike/) for description of the configuration syntax, and GoDoc (https://godoc.org/pkg/github.com/3ofcoins/shlike/) for API details.
Example ¶
// Prepare a new config cfg := NewConfig() // Set some variables cfg.Set("FOO", "bar", "baz") cfg.Append("BAR", "baz") cfg.Append("BAR", "quux") // Evaluate a string... cfg.Eval("So, $FOO $BAR") // One line has been read cfg.Length() // returns: 1 // And it contains variable expansion cfg.Line(0) // returns: {"So,", "bar", "baz", "baz", "quux"} // load a config file cfg.Load("fixtures/example.conf") // Read variables set from configuration cfg.Get("REDIS_PORT") // returns: {"6379"} // Iterate over lines for line := range cfg.Iter() { _ = line // Process the configuration } // Save to a file cfg.Save("final.conf")
Output:
Index ¶
- func Escape(str string) string
- func EscapeLine(strs []string) string
- func EvalInto(cfg Config, source string) error
- func LoadInto(cfg Config, path string) error
- func Serialize(c Config) string
- type Config
- type SimpleConfig
- func (c *SimpleConfig) Append(variable string, values ...string)
- func (c *SimpleConfig) Eval(source string) error
- func (c *SimpleConfig) Get(variable string) []string
- func (c *SimpleConfig) Iter() <-chan []string
- func (c *SimpleConfig) Length() int
- func (c *SimpleConfig) Line(number int) []string
- func (c *SimpleConfig) Load(path string) error
- func (c *SimpleConfig) ReceiveLine(words []string)
- func (c *SimpleConfig) Save(path string) error
- func (c *SimpleConfig) Serialize() string
- func (c *SimpleConfig) Set(variable string, values ...string)
- func (c *SimpleConfig) Unset(variable string)
- func (c *SimpleConfig) Variables() []string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EscapeLine ¶
Returns a string containing `strs` as a line of escaped words
Types ¶
type Config ¶
type Config interface { ReceiveLine(words []string) // Receive a config line from lexer Set(name string, values ...string) // Set variable Append(name string, values ...string) // Append to variable Get(name string) []string // Get variable's value Unset(name string) // Unset variable Variables() []string // List of variable names Length() int // Number of config lines Line(number int) []string // A single line Iter() <-chan []string // Iterator over lines }
A configuration object interface. Can accept variables, dot-commands, and parsed lines from lexer, and exposes them to end user.
type SimpleConfig ¶
type SimpleConfig struct { Vars map[string][]string // Variable values Lines [][]string // Evaluated lines }
An implementation of `Config` interface.
func (*SimpleConfig) Append ¶
func (c *SimpleConfig) Append(variable string, values ...string)
func (*SimpleConfig) Eval ¶
func (c *SimpleConfig) Eval(source string) error
Evaluates `source` configuration string
func (*SimpleConfig) Get ¶
func (c *SimpleConfig) Get(variable string) []string
func (*SimpleConfig) Iter ¶
func (c *SimpleConfig) Iter() <-chan []string
func (*SimpleConfig) Length ¶
func (c *SimpleConfig) Length() int
func (*SimpleConfig) Line ¶
func (c *SimpleConfig) Line(number int) []string
func (*SimpleConfig) Load ¶
func (c *SimpleConfig) Load(path string) error
Loads configuration from `path`
func (*SimpleConfig) ReceiveLine ¶
func (c *SimpleConfig) ReceiveLine(words []string)
func (*SimpleConfig) Save ¶
func (c *SimpleConfig) Save(path string) error
Saves configuration into a file
func (*SimpleConfig) Serialize ¶
func (c *SimpleConfig) Serialize() string
Serializes configuration into a loadable string
func (*SimpleConfig) Set ¶
func (c *SimpleConfig) Set(variable string, values ...string)
func (*SimpleConfig) Unset ¶
func (c *SimpleConfig) Unset(variable string)
func (*SimpleConfig) Variables ¶
func (c *SimpleConfig) Variables() []string