Documentation ¶
Overview ¶
A simple and consistent method to extract a configuration from a file. This doesn't contain any method to actually decode the file. The actual decoding is done in an external function.
Index ¶
Constants ¶
const DefaultPostfix = "_config.json"
Variables ¶
This section is empty.
Functions ¶
func DecodeJsonConfig ¶
Simple JSON based configuration decoder.
func EncodeJsonConfig ¶
Simple JSON based configuration encoder.
func GetConfigFilePath ¶
Return a configuration file path. If baseName is empty, then the current executable name without the extension is used. If postfix is empty then DefaultPostfix is used.
Types ¶
type DecodeConfig ¶
type EncodeConfig ¶
type WatchConfig ¶
type WatchConfig struct { // Notified here if the file changes. C chan *WatchConfig // contains filtered or unexported fields }
func NewWatchConfig ¶
func NewWatchConfig(filepath string, decode DecodeConfig, defaultConfig interface{}, encode EncodeConfig) (*WatchConfig, error)
Create a new configuration watcher. Adds a notification if the configuration file changes so it may be reloaded. If defaultConfig is not nil and encode is not nil, the configuration file path is checked if a file exists or not. If it doesn't exist the default configuration is written to the file.
func (*WatchConfig) Close ¶
func (wc *WatchConfig) Close() error
Stop the watch and any loops that are running.
func (*WatchConfig) Load ¶
func (wc *WatchConfig) Load(v interface{}) error
Load the configuration from the file into the provided value.
func (*WatchConfig) TriggerC ¶
func (wc *WatchConfig) TriggerC()
Send a notification as if the configuration file has changed.