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 ¶
- type CfgBlock
- func (cfg CfgBlock) CfgWrite(_filename string)
- func (cfg *CfgBlock) EditEntry(_tbl, _row, _col, value string)
- func (cfg *CfgBlock) Expandlist(_block, _row, _col, _row2 string) []string
- func (cfg CfgBlock) Float64(_tbl, _row, _col string, _def float64) float64
- func (cfg CfgBlock) GetBlock(_blockPath []string) *CfgBlock
- func (cfg CfgBlock) GetBlocks() []string
- func (cfg CfgBlock) GetCols(_tbl, _row string) []string
- func (cfg CfgBlock) GetRows(_tbl string) []string
- func (cfg CfgBlock) Int(_tbl, _row, _col string, _def int) int
- func (cfg CfgBlock) Int64(_tbl, _row, _col string, _def int64) int64
- func (cfg CfgBlock) NestedFloat64(_tbls []string, _row, _col string, _def float64) float64
- func (cfg CfgBlock) NestedInt(_tbls []string, _row, _col string, _def int) int
- func (cfg CfgBlock) NestedInt64(_tbls []string, _row, _col string, _def int64) int64
- func (cfg CfgBlock) NestedStr(_tbls []string, _row, _col string, _def string) string
- func (cfg CfgBlock) RowExists(block, row string) bool
- func (cfg CfgBlock) SelfFloat64(_row, _col string, _def float64) float64
- func (cfg CfgBlock) SelfInt(_row, _col string, _def int) int
- func (cfg CfgBlock) SelfInt64(_row, _col string, _def int64) int64
- func (cfg CfgBlock) SelfStr(_row, _col string, _def string) string
- func (cfg CfgBlock) Split(_tbl, _row, _col string, _def string) []string
- func (cfg CfgBlock) Str(_tbl, _row, _col string, _def string) string
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 ¶
NewCfg reads ()and parses) a new top-level config file (and recursively any config files that are included)
func NewCfgMem ¶
NewCfgMem creates an empty in-memory representation of a config file. Use it to create config files programmatically
func (CfgBlock) CfgWrite ¶
CfgWrite is used to programmatically create a new config file by writing out its in-memory representation
func (*CfgBlock) EditEntry ¶
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 ¶
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 ¶
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) GetBlocks ¶
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 ¶
GetCols returns a list of names of all columns within a specific rows of a specific block (block)
func (CfgBlock) GetRows ¶
GetRows returns a list of names of all rows within a specific block (block)
func (CfgBlock) 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 ¶
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 ¶
NestedFloat64 applies Float64() on a nested block
func (CfgBlock) NestedInt64 ¶
NestedInt64 applies Int64() on a nested block
func (CfgBlock) RowExists ¶
RowExists is used to verify if a specific row exists within a specific block (block)
func (CfgBlock) SelfFloat64 ¶
SelfFloat64 applies Float64() on self