Documentation ¶
Index ¶
- func AddSetting(path string, val interface{})
- func AddSettingDecoder(dec SettingDecoder)
- func AddSettingListener(callback func()) int64
- func ClearSettings()
- func GetSetting(path string) interface{}
- func GetSettingBool(path string) bool
- func GetSettingInt(path string) int
- func GetSettingString(path string) string
- func HasSetting(path string) bool
- func LoadSettingsFromFile(path string) error
- func ParseSettings() error
- func RemoveAllSettingDecoders()
- func RemoveSettingDecoder(dec SettingDecoder)
- func RemoveSettingListener(callbackKey int64)
- func WaitForReload(reloadFifoFile string) chan bool
- func WatchConfigurationFile(configFilePath string) chan bool
- type BasicSettingDecoder
- type FunctionalSettingDecoder
- type SettingDecoder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddSetting ¶
func AddSetting(path string, val interface{})
AddSetting adds a new setting to the settings map.
func AddSettingDecoder ¶
func AddSettingDecoder(dec SettingDecoder)
AddSettingDecoder adds new setting decoder to the decoder list These decoders will be used to interpret the JSON configuration file when ParseSettings() is called
func AddSettingListener ¶
func AddSettingListener(callback func()) int64
AddSettingListener adds a callback function to be called on setting change. An integer value is returned this is the key / handle you will use to latter delete the listener
func ClearSettings ¶
func ClearSettings()
ClearSettings clears all settings. call this before re-parsing
func GetSetting ¶
func GetSetting(path string) interface{}
GetSetting return the requested setting or nil.
func GetSettingBool ¶
GetSettingBool is like GetSetting but it retruns a bool or bool {} (zero value) if the key is not found.
func GetSettingInt ¶
GetSettingInt is like GetSetting but it retruns a int or int {} (zero value) if the key is not found.
func GetSettingString ¶
GetSettingString like GetSetting but it returns a string or string{} (zero value) if the key is not found.
func HasSetting ¶
HasSetting checks for the existence of the setting denoted by path
func LoadSettingsFromFile ¶
LoadSettingsFromFile loads a new setting structure form a JSON configuration file. After calling this said structure must be interpreted by calling ParseSettings().
func ParseSettings ¶
func ParseSettings() error
ParseSettings parse the setting structure loaded with LoadSettingsFromFile() by using the decoders specified with AddSettingDecoder().
func RemoveAllSettingDecoders ¶
func RemoveAllSettingDecoders()
RemoveAllSettingDecoders removes all setting decoders
func RemoveSettingDecoder ¶
func RemoveSettingDecoder(dec SettingDecoder)
RemoveSettingDecoder remove a setting decoder from the list of setting decoders by pointer
func RemoveSettingListener ¶
func RemoveSettingListener(callbackKey int64)
RemoveSettingListener removes a callback by provided key / handle.
func WaitForReload ¶
WaitForReload waits for the reload command on the configured fifo file. most often this would be invoked with "systemctl reload microweb" return: a channel close this channel to stop waiting for reload
func WatchConfigurationFile ¶
WatchConfigurationFile starts watching the configuration file for changes. if it does change, realod the settings. returns a done channel, close this channel to stop watching the configuration file
Types ¶
type BasicSettingDecoder ¶
type BasicSettingDecoder struct {
// contains filtered or unexported fields
}
BasicSettingDecoder is a dumb decoder that simpily decodes things by returning them. It will only decode if path matches.
func (*BasicSettingDecoder) CanDecodeSetting ¶
func (dec *BasicSettingDecoder) CanDecodeSetting(path string) bool
CanDecodeSetting returns true if the objects internal path param matches path
func (*BasicSettingDecoder) DecodeSetting ¶
func (dec *BasicSettingDecoder) DecodeSetting(s interface{}) (string, interface{})
DecodeSetting decodes a setting by simpily returning it. return:
setting name as dictated by path name, the interface that was passed in.
type FunctionalSettingDecoder ¶
type FunctionalSettingDecoder struct {
// contains filtered or unexported fields
}
FunctionalSettingDecoder a setting decoder that takes user provided functions for both decode and canDecode operations.
func (*FunctionalSettingDecoder) CanDecodeSetting ¶
func (dec *FunctionalSettingDecoder) CanDecodeSetting(path string) bool
CanDecodeSetting decide if this object can handle this setting path based on user provided function
func (*FunctionalSettingDecoder) DecodeSetting ¶
func (dec *FunctionalSettingDecoder) DecodeSetting(s interface{}) (string, interface{})
DecodeSetting decode the setting item based on user provided function
type SettingDecoder ¶
type SettingDecoder interface { DecodeSetting(s interface{}) (string, interface{}) CanDecodeSetting(path string) bool }
SettingDecoder is the interface to which all setting decoders comply. A setting decoder is a struct with methods for decoding JSON setting information.
func NewBasicDecoder ¶
func NewBasicDecoder(path string) SettingDecoder
NewBasicDecoder returns a decoder that performs dumb decoding on any setting matching path. An example path would be: "general/TCPProtocol".
func NewFunctionalSettingDecoder ¶
func NewFunctionalSettingDecoder(decodeFunc func(s interface{}) (string, interface{}), canDecodeFunc func(path string) bool) SettingDecoder
NewFunctionalSettingDecoder constructs a new functional decoder with the provided user decode and canDecode functions