Documentation ¶
Overview ¶
Package config has helpers to parse and use JSON based configuration.
Index ¶
- Variables
- func CompareConfig(config1, config2 interface{}) ([]string, error)
- func LoadFile(p, baseDir string) ([]byte, error)
- func ReadConfig(r io.Reader, destConfig interface{}) error
- func ReadFiles(destConfig interface{}, cfgFpaths ...string) error
- func ReadFilesDefaults(destConfig interface{}, defls map[string]interface{}, cfgFpaths ...string) error
- func UnmarshalJSONViaString(dest FromString, b []byte) error
- type ConfigHostPort
- type ConfigQueueSize
- type ConfigTimeDuration
- type FromString
Constants ¶
This section is empty.
Variables ¶
var IgnoreParsedFlags = false
IgnoreParsedFlags will just have ReadFiles ignore <flags> if the command line was already parsed.
Functions ¶
func CompareConfig ¶
CompareConfigs compares the two given configuration structures. It returns a list of differing fields or nil if the config contents are the same.
func LoadFile ¶
LoadFile reads a file possibly relative to a base dir.
func ReadConfig ¶
ReadConfig reads a JSON configuration into destConfig which should be a pointer to a structure. It does some more configuration specific error checking than plain JSON decoding, and mentions fields in errors. Configuration fields in the JSON object are expected to start with lower case.
func ReadFiles ¶
ReadFiles reads configuration from a set of files exactly like ReadFilesDefaults but no defaults can be given making all fields mandatory.
func ReadFilesDefaults ¶
func ReadFilesDefaults(destConfig interface{}, defls map[string]interface{}, cfgFpaths ...string) error
ReadFilesDefaults reads configuration from a set of files. The string "<flags>" can be used as a pseudo file-path, it will consider command line flags, invoking flag.Parse(). Among those the flag -cfg@=FILE can be used to get further config values from FILE. Defaults for fields can be given through a map[string]interface{}.
func UnmarshalJSONViaString ¶
func UnmarshalJSONViaString(dest FromString, b []byte) error
UnmarshalJSONViaString helps unmarshalling from JSON for FromString supporting config holders.
Types ¶
type ConfigHostPort ¶
type ConfigHostPort string
ConfigHostPort can hold a host:port string in a configuration struct.
func (ConfigHostPort) HostPort ¶
func (chp ConfigHostPort) HostPort() string
HostPort returns the host:port string held in chp.
func (*ConfigHostPort) SetFromString ¶
func (chp *ConfigHostPort) SetFromString(enc string) error
func (*ConfigHostPort) UnmarshalJSON ¶
func (chp *ConfigHostPort) UnmarshalJSON(b []byte) error
type ConfigQueueSize ¶
type ConfigQueueSize uint
ConfigQueueSize can hold a queue size in a configuration struct.
func (ConfigQueueSize) QueueSize ¶
func (cqs ConfigQueueSize) QueueSize() uint
QueueSize returns the queue size held in cqs.
func (*ConfigQueueSize) UnmarshalJSON ¶
func (cqs *ConfigQueueSize) UnmarshalJSON(b []byte) error
type ConfigTimeDuration ¶
ConfigTimeDuration can hold a time.Duration in a configuration struct, that is parsed from a string as supported by time.ParseDuration.
func (*ConfigTimeDuration) SetFromString ¶
func (ctd *ConfigTimeDuration) SetFromString(enc string) error
func (ConfigTimeDuration) TimeDuration ¶
func (ctd ConfigTimeDuration) TimeDuration() time.Duration
TimeDuration returns the time.Duration held in ctd.
func (*ConfigTimeDuration) UnmarshalJSON ¶
func (ctd *ConfigTimeDuration) UnmarshalJSON(b []byte) error