Documentation ¶
Index ¶
- type YCfg
- func (yc *YCfg) AllSettings() map[string]interface{}
- func (yc *YCfg) AllSettingsAsStrings() map[string]string
- func (yc *YCfg) Clear()
- func (yc *YCfg) Delete(key string)
- func (yc *YCfg) Get(key string, settings map[string]string) ([]YCfgEntry, error)
- func (yc *YCfg) GetFirst(key string, settings map[string]string) (YCfgEntry, bool, error)
- func (yc *YCfg) GetFirstVal(key string, settings map[string]string) (interface{}, error)
- func (yc *YCfg) GetSlice(key string, settings map[string]string) ([]YCfgEntry, error)
- func (yc *YCfg) GetStringMap(key string, settings map[string]string) (map[string]YCfgEntry, error)
- func (yc *YCfg) GetStringMapString(key string, settings map[string]string) (map[string]YCfgEntry, error)
- func (yc *YCfg) GetStringSlice(key string, settings map[string]string) ([]YCfgEntry, error)
- func (yc *YCfg) GetValBool(key string, settings map[string]string) (bool, error)
- func (yc *YCfg) GetValBoolDflt(key string, settings map[string]string, dflt bool) (bool, error)
- func (yc *YCfg) GetValInt(key string, settings map[string]string) (int, error)
- func (yc *YCfg) GetValSlice(key string, settings map[string]string) ([]interface{}, error)
- func (yc *YCfg) GetValString(key string, settings map[string]string) (string, error)
- func (yc *YCfg) GetValStringMap(key string, settings map[string]string) (map[string]interface{}, error)
- func (yc *YCfg) GetValStringMapString(key string, settings map[string]string) (map[string]string, error)
- func (yc *YCfg) GetValStringSlice(key string, settings map[string]string) ([]string, error)
- func (yc *YCfg) GetValStringSliceNonempty(key string, settings map[string]string) ([]string, error)
- func (yc *YCfg) HasKey(key string) bool
- func (yc *YCfg) MergeFromFile(key string, val interface{}, fileInfo *util.FileInfo) error
- func (yc *YCfg) Replace(key string, val interface{}) error
- func (yc *YCfg) ReplaceFromFile(key string, val interface{}, fileInfo *util.FileInfo) error
- func (yc *YCfg) String() string
- func (yc *YCfg) Traverse(cb func(node *YCfgNode, depth int))
- func (yc *YCfg) Tree() YCfgTree
- func (yc *YCfg) YAML() string
- type YCfgEntry
- type YCfgNode
- type YCfgTree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type YCfg ¶
type YCfg struct {
// contains filtered or unexported fields
}
YAML configuration object. This is a substitute for a viper configuration object, with the following newt-specific advantages: 1. Case sensitive. 2. Efficient conditionals based on syscfg values.
A single YCfg setting is implemented as a tree of nodes. Each word in the setting name represents a node; each "." in the name is a link in the tree. For example, the following syscfg lines:
OS_MAIN_STACK_SIZE: 100 OS_MAIN_STACK_SIZE.BLE_DEVICE: 200 OS_MAIN_STACK_SIZE.SHELL_TASK: 300
Is represented as the following tree:
[OS_MAIN_STACK_SIZE (100)] / \ [BLE_DEVICE (200)] [SHELL_TASK (300)]
This allows us to quickly determine the value of OS_MAIN_STACK_SIZE. After finding the OS_MAIN_STACK_SIZE node, the logic is something like this:
Is BLE_DEVICE true? --> 200 Is SHELL_TASK true? --> 300 Else: --> 100
The tree structure also allows for arbitrary expressions as conditionals, as opposed to simple setting names. For example:
OS_MAIN_STACK_SIZE: 100 OS_MAIN_STACK_SIZE.'(BLE_DEVICE && !SHELL_TASK): 200 OS_MAIN_STACK_SIZE.'(SHELL_TASK && !BLE_DEVICE): 300 OS_MAIN_STACK_SIZE.'(SHELL_TASK && BLE_DEVICE): 400
Since each expression is a child node of the setting in question, they are all known at the time of the lookup. To determine the value of the setting, each expression is parsed, and only the one evaluating to true is selected.
func (*YCfg) AllSettings ¶
AllSettings converts the YCfg into a map with the following form:
<node-full-name>: <node-value>
func (*YCfg) AllSettingsAsStrings ¶
AllSettingsAsStrings converts the YCfg into a map with the following form:
<node-full-name>: <node-value>
All values in the map have been coerced to strings.
func (*YCfg) Get ¶
Get retrieves all nodes with the specified key. If it encounters a parse error in the tree, it ignores the bad node and continues the search. All bad nodes are indicated in the returned error. In this sense, the returned object is valid even if there is an error, and the error can be thought of as a set of warnings.
func (*YCfg) GetFirst ¶
GetFirst retrieves the first entry with the specified key. The bool return value is true if a matching entry was found. The returned error is a set of warnings just as in `Get`.
func (*YCfg) GetFirstVal ¶
GetFirstVal retrieves the first entry with the specified key and returns its value. It returns nil if no matching entry is found. The returned error is a set of warnings just as in `Get`.
func (*YCfg) GetSlice ¶
GetSlice retrieves all entries with the specified key and coerces their values to type []interface{}. The returned []YCfgEntry is formed from the union of all these slices. The returned error is a set of warnings just as in `Get`.
func (*YCfg) GetStringMap ¶
GetStringMap retrieves all entries with the specified key and coerces their values to type map[string]interface{}. The returned map[string]YCfgEntry is formed from the union of all these maps. The returned error is a set of warnings just as in `Get`.
func (*YCfg) GetStringMapString ¶
func (yc *YCfg) GetStringMapString(key string, settings map[string]string) (map[string]YCfgEntry, error)
GetStringMapString retrieves all entries with the specified key and coerces their values to type map[string]string. The returned map[string]YCfgEntry is formed from the union of all these maps. The returned error is a set of warnings just as in `Get`.
func (*YCfg) GetStringSlice ¶
GetStringSlice retrieves all entries with the specified key and coerces their values to type []string. The returned []YCfgEntry is formed from the union of all these slices. The returned error is a set of warnings just as in `Get`.
func (*YCfg) GetValBool ¶
GetValBoolDflt retrieves the first entry with the specified key and returns its value coerced to a bool. It returns false if no matching entry is found. The returned error is a set of warnings just as in `Get`.
func (*YCfg) GetValBoolDflt ¶
GetValBoolDflt retrieves the first entry with the specified key and returns its value coerced to a bool. It returns the specified default if no matching entry is found. The returned error is a set of warnings just as in `Get`.
func (*YCfg) GetValInt ¶
GetValInt retrieves the first entry with the specified key and returns its value coerced to an int. It returns 0 if no matching entry is found. The returned error is a set of warnings just as in `Get`.
func (*YCfg) GetValSlice ¶
GetValSlice retrieves all entries with the specified key and coerces their values to type []interface{}. The returned slice is the union of all these slices. The returned error is a set of warnings just as in `Get`.
func (*YCfg) GetValString ¶
GetValString retrieves the first entry with the specified key and returns its value coerced to a string. It returns "" if no matching entry is found. The returned error is a set of warnings just as in `Get`.
func (*YCfg) GetValStringMap ¶
func (yc *YCfg) GetValStringMap( key string, settings map[string]string) (map[string]interface{}, error)
GetValStringMap retrieves all entries with the specified key and coerces their values to type map[string]interface{}. The returned map[string]YCfgEntry is the union of all these maps. The returned error is a set of warnings just as in `Get`.
func (*YCfg) GetValStringMapString ¶
func (yc *YCfg) GetValStringMapString(key string, settings map[string]string) (map[string]string, error)
GetStringMapString retrieves all entries with the specified key and coerces their values to type map[string]string. The returned map[string]YCfgEntry is the union of all these maps. The returned error is a set of warnings just as in `Get`.
func (*YCfg) GetValStringSlice ¶
GetValStringSlice retrieves all entries with the specified key and coerces their values to type []string. The returned []string is the union of all these slices. The returned error is a set of warnings just as in `Get`.
func (*YCfg) GetValStringSliceNonempty ¶
func (yc *YCfg) GetValStringSliceNonempty( key string, settings map[string]string) ([]string, error)
GetValStringSliceNonempty retrieves all entries with the specified key and coerces their values to type []string. The returned []string is the union of all these slices. Empty strings are excluded from this union. The returned error is a set of warnings just as in `Get`.
func (*YCfg) MergeFromFile ¶
MergeFromFile merges the given value into a tree node. Only two value types can be merged:
map[interface{}]interface{} []interface{}
The node's current value must have the same type as the value being merged. In the map case, each key-value pair in the given value is inserted into the current value, overwriting as necessary. In the slice case, the given value is appended to the current value.
If no node with the specified key exists, a new node is created containing the given value.