Documentation ¶
Overview ¶
Package dynconfig provides routines for implementing dynamic configuration files.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DynConfig ¶
type DynConfig struct {
// contains filtered or unexported fields
}
DynConfig represents a dynamic configuration file. Caller creates a DynConfig instance by caling New or NewInitialized at startup. Then caller keeps the DynConfig instance around throughout the duration of execution. When caller needs the end product of the configuration file, caller calls Get() on the DynConfig instance.
func New ¶
func New( path string, builder func(io.Reader) (interface{}, error), name string, logger log.Logger) *DynConfig
builder builds the end product from the configuration file contents. builder takes the contents of the configuration file as input and outputs either the final end product or an error. builder is called each time the configuration file changes.
name is the the name of the configuration file and is used as a log prefix logger is where any errors reading the configuration get logged.
func NewInitialized ¶
func NewInitialized( path string, builder func(io.Reader) (interface{}, error), name string, logger log.Logger) (*DynConfig, error)
NewInitialized works like New except that if the configuration file doesn't exist or the end product can't be built, it returns an error instead of a new DynConfig instance. If NewInitialized returns a DynConfig instance, its Get method is guaranteed to return a non-nil value.
func (*DynConfig) Get ¶
func (d *DynConfig) Get() interface{}
Get returns the end product of the configuration file. If the configuration file changes during runtime, Get will return a different end product that reflects the updated configuration file. If the configuration file is updated so that it contains an error such that no end product can be created from it, Get continues to return the previous end product. If the DynConfig instance was created with New and the config file doesn't exist or couldn't be parsed initially, then Get returns nil until such time that the configuration file errors get fixed.