config

package
v0.0.0-...-95af53b Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2015 License: Zlib Imports: 7 Imported by: 1

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

View Source
const DefaultPostfix = "_config.json"

Variables

This section is empty.

Functions

func DecodeJsonConfig

func DecodeJsonConfig(r io.Reader, v interface{}) error

Simple JSON based configuration decoder.

func EncodeJsonConfig

func EncodeJsonConfig(w io.Writer, v interface{}) error

Simple JSON based configuration encoder.

func GetConfigFilePath

func GetConfigFilePath(baseName, postfix string) (string, error)

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 DecodeConfig func(r io.Reader, v interface{}) error

type EncodeConfig

type EncodeConfig func(w io.Writer, v interface{}) error

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.

Jump to

Keyboard shortcuts

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