qcfg

package module
v0.0.0-...-4b50333 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2016 License: GPL-3.0 Imports: 6 Imported by: 7

README

qcfg

qcfg is a go pkg for reading a specific config file format into memory, query its elements, and write the representation to file

GoDoc

Documentation

Overview

Package qcfg provides for reading a specific config file format into memory, query its elements, and write the representation to file.

The format is tuned for ease of creation/maintenance of configuration of applications written in certain languages by a specific set of people.

Candidates passed over include XML (human-unreadable), JSON (quote-burdened), Unix ini files (unhierarchical), Java properties files (unhierarchical), YAML (indentatious), eval'ed code (language specific).

One could easily implement a diff program to highlight non-cosmetic changes (whitespace, comments and file/row/block reordering) to be used prior to checkin of config changes.

The format is plain text with named blocks as the main construct. Blocks contain named rows, and rows contained named columns. Blocks can also contain named blocks, hence the hierarchy. Blocks require 3 lines to define.

(1) A line containing "%block SomeBlockName" which names the block. (2) An immediately following line with an opening "{". (3) After its content ends, a line containing a closing "}"

At any point, files may include other files using "%include /some/other/file". This facilitates sharing common config between apps.

While it should work otherwise, maintainability dictates you should

(1) put the blockname and its opening/closing parens as well as the lines defining the ROWS of the block WITHIN THE SAME FILE. (2) use the %include file directive to include the definition of large embedded block hierarchies. (3) use the %include file directive to include the definition of several blocks that have related meaning.

Whitespace at beginning of line or end of line is ignored. Comments start at the Hash char (#) and extend to EOL. Empty lines are ignored. Block, row and column names are trimmed, so also column values.

Rows are defined by rowname on the left followed by "::" followed by list of column name=val pairs, each terminated by semi-colon. Rows may be continued to the next line by the appearance of "+=" on the left of further column name-val pairs.

Env-variable substitution is not yet implemented.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CfgBlock

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

CfgBlock struct holds the in-memory representation of a top-level config file

func NewCfg

func NewCfg(_name string, _fname string, _verbose bool) *CfgBlock

NewCfg reads ()and parses) a new top-level config file (and recursively any config files that are included)

func NewCfgMem

func NewCfgMem(_name string) *CfgBlock

NewCfgMem creates an empty in-memory representation of a config file. Use it to create config files programmatically

func (CfgBlock) CfgWrite

func (cfg CfgBlock) CfgWrite(_filename string)

CfgWrite is used to programmatically create a new config file by writing out its in-memory representation

func (*CfgBlock) EditEntry

func (cfg *CfgBlock) EditEntry(_tbl, _row, _col, value string)

EditEntry updates en element of the in-memory representation of a config file. Use it to modify the configuration for subsequent use of the instance, or in preparation to write a modified config file

func (*CfgBlock) Expandlist

func (cfg *CfgBlock) Expandlist(_block, _row, _col, _row2 string) []string

Expandlist is a shorthand method If box.row.col == "foo1,foo2,..." then return unique list of {box.row2.foo1, box.row2.foo2, ...}

func (CfgBlock) Float64

func (cfg CfgBlock) Float64(_tbl, _row, _col string, _def float64) float64

Float64 is used to query an element of the in-memory representation of the config file, as type float64. It returns the specified default if the element is missing

func (CfgBlock) GetBlock

func (cfg CfgBlock) GetBlock(_blockPath []string) *CfgBlock

GetBlock returns the block found by following down a block hierarchy

func (CfgBlock) GetBlocks

func (cfg CfgBlock) GetBlocks() []string

GetBlocks returns a list of names of all the blocks (aka blocks) within the current block Use it when you want to process an entire config file

func (CfgBlock) GetCols

func (cfg CfgBlock) GetCols(_tbl, _row string) []string

GetCols returns a list of names of all columns within a specific rows of a specific block (block)

func (CfgBlock) GetRows

func (cfg CfgBlock) GetRows(_tbl string) []string

GetRows returns a list of names of all rows within a specific block (block)

func (CfgBlock) Int

func (cfg CfgBlock) Int(_tbl, _row, _col string, _def int) int

Int is used to query an element of the in-memory representation of the config file, as type int. It returns the specified default if the element is missing

func (CfgBlock) Int64

func (cfg CfgBlock) Int64(_tbl, _row, _col string, _def int64) int64

Int64 is used to query an element of the in-memory representation of the config file, as type int64. It returns the specified default if the element is missing

func (CfgBlock) NestedFloat64

func (cfg CfgBlock) NestedFloat64(_tbls []string, _row, _col string, _def float64) float64

NestedFloat64 applies Float64() on a nested block

func (CfgBlock) NestedInt

func (cfg CfgBlock) NestedInt(_tbls []string, _row, _col string, _def int) int

NestedInt applies Int() on a nested block

func (CfgBlock) NestedInt64

func (cfg CfgBlock) NestedInt64(_tbls []string, _row, _col string, _def int64) int64

NestedInt64 applies Int64() on a nested block

func (CfgBlock) NestedStr

func (cfg CfgBlock) NestedStr(_tbls []string, _row, _col string, _def string) string

NestedStr applies Str() on a nested block

func (CfgBlock) RowExists

func (cfg CfgBlock) RowExists(block, row string) bool

RowExists is used to verify if a specific row exists within a specific block (block)

func (CfgBlock) SelfFloat64

func (cfg CfgBlock) SelfFloat64(_row, _col string, _def float64) float64

SelfFloat64 applies Float64() on self

func (CfgBlock) SelfInt

func (cfg CfgBlock) SelfInt(_row, _col string, _def int) int

SelfInt applies Int() on self

func (CfgBlock) SelfInt64

func (cfg CfgBlock) SelfInt64(_row, _col string, _def int64) int64

SelfInt64 applies Int64() on self

func (CfgBlock) SelfStr

func (cfg CfgBlock) SelfStr(_row, _col string, _def string) string

SelfStr applies Str() on self

func (CfgBlock) Split

func (cfg CfgBlock) Split(_tbl, _row, _col string, _def string) []string

Split is shorthand for csv-splitting the output of qcfg packages Str func

func (CfgBlock) Str

func (cfg CfgBlock) Str(_tbl, _row, _col string, _def string) string

Str is used to query an element of the in-memory representation of the config file, as type string. It returns the specified default if the element is missing

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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