config

package
v0.0.0-...-0000000 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2017 License: GPL-3.0, GPL-3.0 Imports: 13 Imported by: 5

Documentation

Overview

Package config has helpers to parse and use JSON based configuration.

Index

Constants

This section is empty.

Variables

View Source
var IgnoreParsedFlags = false

IgnoreParsedFlags will just have ReadFiles ignore <flags> if the command line was already parsed.

Functions

func CompareConfig

func CompareConfig(config1, config2 interface{}) ([]string, error)

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

func LoadFile(p, baseDir string) ([]byte, error)

LoadFile reads a file possibly relative to a base dir.

func ReadConfig

func ReadConfig(r io.Reader, destConfig interface{}) error

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

func ReadFiles(destConfig interface{}, cfgFpaths ...string) error

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

type ConfigTimeDuration struct {
	time.Duration
}

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

type FromString

type FromString interface {
	SetFromString(enc string) error
}

FromString are config holders that can be set by parsing a string.

Jump to

Keyboard shortcuts

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