mwsettings

package
v0.0.0-...-6b4cc3a Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2019 License: MIT Imports: 12 Imported by: 6

Documentation

Index

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

func GetSettingBool(path string) bool

GetSettingBool is like GetSetting but it retruns a bool or bool {} (zero value) if the key is not found.

func GetSettingInt

func GetSettingInt(path string) int

GetSettingInt is like GetSetting but it retruns a int or int {} (zero value) if the key is not found.

func GetSettingString

func GetSettingString(path string) string

GetSettingString like GetSetting but it returns a string or string{} (zero value) if the key is not found.

func HasSetting

func HasSetting(path string) bool

HasSetting checks for the existence of the setting denoted by path

func LoadSettingsFromFile

func LoadSettingsFromFile(path string) error

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

func WaitForReload(reloadFifoFile string) chan bool

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

func WatchConfigurationFile(configFilePath string) chan bool

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

Jump to

Keyboard shortcuts

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