Documentation ¶
Overview ¶
Package uconfig enables access to the configuration loaded by uboot / golum.
This is typically YAML that looks like this:
properties: key: value anInt: 10 autoreload: true debug: components: - name: instanceName type: serviceType note: a note about this disabled: false hosts: ["optional", "hosts", "enabled", "on"] config: foo: 1 bar: hello there sub: foo: 2 bar: "{{.key}}" array: - foo: "{{.anInt}}" bar: array element 0 - foo: 5 bar: array element 1 ... - name: instance2Name type: service2Type config: ...
Properties ¶
The properties section provides substitutable values that can be used in later sections. Properties can use substitutions from other properties.
As string values are accessed, the values also become properties for expanding later accessed string values.
Expansion occurs when a string value contains ${VAR} or {{.KEY}}.
The ${VAR} will be filled in with ENV variables, if available.
The {{.KEY}} will be filled in with properties as per the go text/template package.
properties: key: value fromEnv: ${ENV_VAR} basedOnKey: {{.key}} # NOTE: the '.' is critical
All golang text template rules apply.
The following properties are automatically added:
- homeDir - the home dir of the user
- thisUser - the username of the user
- thisHost - the hostname (nodename) of the host
- thisIp - the first listed (non loopback) IP
- thisProcess - the process name of the process
- thisDir - where the process is installed
- initDir - where the process is started from
Includes ¶
Other files can be included with the 'include_' directive, as in:
include_: /path/to/file.yml
Sections ¶
Each component has a config section. A config section may contain sub-sections and arrays of sub-sections.
Index ¶
- Constants
- Variables
- func Assign(name string, dst, src any) (err error)
- func EnsureAddr(defaultHost, defaultPort, addr string) (rv string, err error)
- func Float64FromBitRateString(s string) (rv float64, err error)
- func Float64FromByteSizeString(s string) (rv float64, err error)
- func Float64FromSiString(s string) (rv float64, err error)
- func InitEnv() (err error)
- func IntFromBitRateString[I Int](s string, rv *I) (err error)
- func IntFromByteSizeString[I Int](s string, rv *I) (err error)
- func IntFromSiString[I Int](s string, rv *I) (err error)
- func IsLocalUrl(url *nurl.URL) bool
- func IsThisHost(host string) bool
- func UIntFromBitRateString[U UInt](s string, rv *U) (err error)
- func UIntFromByteSizeString[U UInt](s string, rv *U) (err error)
- func UIntFromSiString[U UInt](s string, rv *U) (err error)
- func UserInfo() (userName string, homeD string)
- func ValidHostname(s string) bool
- func YamlLoad(file string, target any) (err error)
- type Array
- type Builder
- type Chain
- func (this *Chain) ASection(key string, visitor Visitor) *Chain
- func (this *Chain) Build(value any, builder Builder) *Chain
- func (this *Chain) BuildFrom(key string, value any, builder Builder) *Chain
- func (this *Chain) BuildIf(key string, value any, builder Builder) *Chain
- func (this *Chain) Construct(target Constructable) *Chain
- func (this *Chain) ConstructFrom(key string, target Constructable) *Chain
- func (this *Chain) ConstructIf(key string, target Constructable) *Chain
- func (this *Chain) Done() error
- func (this *Chain) DumpProps() string
- func (this *Chain) Each(key string, builder ChainVisitor) *Chain
- func (this *Chain) EachIf(key string, builder ChainVisitor) *Chain
- func (this *Chain) EachSection(key string, visitor Visitor) *Chain
- func (this *Chain) EachSectionIf(key string, visitor Visitor) *Chain
- func (this *Chain) FailExtraKeys(allowedKeys ...string) *Chain
- func (this *Chain) GetArray(key string, value **Array) *Chain
- func (this *Chain) GetArrayIf(key string, value **Array) *Chain
- func (this *Chain) GetBitRate(key string, result any, validators ...IntValidator) *Chain
- func (this *Chain) GetBool(key string, value *bool) *Chain
- func (this *Chain) GetByteSize(key string, result any, validators ...IntValidator) *Chain
- func (this *Chain) GetChain(key string, value **Chain) *Chain
- func (this *Chain) GetCreateDir(key string, value *string, perm os.FileMode) *Chain
- func (this *Chain) GetDuration(key string, value *time.Duration) *Chain
- func (this *Chain) GetFloat64(key string, value *float64, validators ...FloatValidator) *Chain
- func (this *Chain) GetInt(key string, result any, validators ...IntValidator) *Chain
- func (this *Chain) GetInts(key string, result *[]int, validators ...IntValidator) *Chain
- func (this *Chain) GetIt(key string, value *any) *Chain
- func (this *Chain) GetMillis(key string, value *int64, validators ...IntValidator) *Chain
- func (this *Chain) GetPath(key string, value *string) *Chain
- func (this *Chain) GetPosInt(key string, value *int) *Chain
- func (this *Chain) GetRawString(key string, result *string, validators ...StringValidator) *Chain
- func (this *Chain) GetRegexp(key string, value **regexp.Regexp) *Chain
- func (this *Chain) GetRegexpIf(key string, value **regexp.Regexp) *Chain
- func (this *Chain) GetSection(key string, value **Section) *Chain
- func (this *Chain) GetSectionIf(key string, value **Section) *Chain
- func (this *Chain) GetString(key string, result *string, validators ...StringValidator) *Chain
- func (this *Chain) GetStringMap(key string, value *map[string]string) *Chain
- func (this *Chain) GetStrings(key string, result *[]string, validators ...StringValidator) *Chain
- func (this *Chain) GetUInt(key string, result any, validators ...UIntValidator) *Chain
- func (this *Chain) GetUrl(key string, value **nurl.URL, validators ...StringValidator) *Chain
- func (this *Chain) GetUrlIf(key string, value **nurl.URL, validators ...StringValidator) *Chain
- func (this *Chain) GetValidInt(key string, invalid int, value *int) *Chain
- func (this *Chain) GetValidIt(key string, value *any) *Chain
- func (this *Chain) GetValidPath(key string, value *string) *Chain
- func (this *Chain) If(key string, builder ChainVisitor) *Chain
- func (this *Chain) IfHasKeysIn(f ChainVisitor, keys ...string) *Chain
- func (this *Chain) IfHasKeysMatching(f ChainVisitor, r *regexp.Regexp) *Chain
- func (this *Chain) IfSection(key string, visitor Visitor) *Chain
- func (this *Chain) Must(key string, builder ChainVisitor) *Chain
- func (this *Chain) OnlyKeys(allowedKeys ...string) *Chain
- func (this *Chain) Then(fn func()) *Chain
- func (this *Chain) ThenCheck(fn func() (err error)) *Chain
- func (this *Chain) WarnExtraKeys(allowedKeys ...string) *Chain
- type ChainVisitor
- type Constructable
- type FloatValidator
- type Help
- func (this *Help) AddSub(title string) (sub *Help)
- func (this *Help) AsYaml() (content []byte, err error)
- func (this *Help) Contains(key string) bool
- func (this *Help) Default(value any) (rv *Help)
- func (this *Help) Get(key string) (rv any)
- func (this *Help) GetHelp(key string) (rv *Help)
- func (this *Help) Init(name, note string) (rv *Help)
- func (this *Help) NewItem(name, theType, note string) (rv *Help)
- func (this *Help) Optional() (rv *Help)
- func (this *Help) Set(key string, value any) (rv *Help)
- func (this *Help) SetDefault(value any) (rv *Help)
- func (this *Help) SetOptional() (rv *Help)
- type Int
- type IntValidator
- type Section
- func (this *Section) Add(key string, value any)
- func (this *Section) AddProp(key, value string)
- func (this *Section) AddProps(props map[string]string)
- func (this *Section) AnyKeysIn(keys ...string) bool
- func (this *Section) AnyKeysMatch(r *regexp.Regexp) bool
- func (this *Section) AsResolvedMap() (rv map[string]any)
- func (this *Section) Chain() *Chain
- func (this *Section) CloneProps() map[string]string
- func (this *Section) Contains(key string) (found bool)
- func (this *Section) DiffersFrom(that *Section) (differs bool)
- func (this *Section) DumpProps() (rv string)
- func (this *Section) DumpVals() (rv string)
- func (this *Section) Each(fn func(key string, val any) error) error
- func (this *Section) EachString(fn func(key, val string) error) (err error)
- func (this *Section) Expand(text string) string
- func (this *Section) ExtraKeys(allowedKeys []string) (rv []string)
- func (this *Section) FailExtraKeys(allowedKeys ...string)
- func (this *Section) GetArray(key string, result **Array) (err error)
- func (this *Section) GetArrayIf(key string, result **Array) (err error)
- func (this *Section) GetBitRate(key string, result any, validators ...IntValidator) (err error)
- func (this *Section) GetBool(key string, result *bool) (err error)
- func (this *Section) GetByteSize(key string, result any, validators ...IntValidator) (err error)
- func (this *Section) GetChain(key string) (rv *Chain)
- func (this *Section) GetCreateDir(key string, val *string, perm os.FileMode) (err error)
- func (this *Section) GetDuration(key string, val *time.Duration) (err error)
- func (this *Section) GetFloat64(key string, val *float64, validators ...FloatValidator) (err error)
- func (this *Section) GetInt(key string, result any, validators ...IntValidator) (err error)
- func (this *Section) GetInts(key string, result *[]int, validators ...IntValidator) (err error)
- func (this *Section) GetIt(key string, value *any)
- func (this *Section) GetMillis(key string, val *int64, validators ...IntValidator) (err error)
- func (this *Section) GetPath(key string, result *string) (err error)
- func (this *Section) GetPosInt(key string, result *int) (err error)
- func (this *Section) GetRawString(key string, result *string, validators ...StringValidator) (err error)
- func (this *Section) GetRegexp(key string, result **regexp.Regexp) (err error)
- func (this *Section) GetRegexpIf(key string, result **regexp.Regexp) (err error)
- func (this *Section) GetSection(key string, result **Section) (err error)
- func (this *Section) GetSectionIf(key string, val **Section) (err error)
- func (this *Section) GetString(key string, result *string, validators ...StringValidator) (err error)
- func (this *Section) GetStringMap(key string, val *map[string]string) (err error)
- func (this *Section) GetStrings(key string, result *[]string, validators ...StringValidator) (err error)
- func (this *Section) GetStruct(key string, dst any) (err error)
- func (this *Section) GetUInt(key string, result any, validators ...UIntValidator) (err error)
- func (this *Section) GetUrl(key string, result **nurl.URL, validators ...StringValidator) (err error)
- func (this *Section) GetUrlIf(key string, result **nurl.URL, validators ...StringValidator) (err error)
- func (this *Section) GetValidInt(key string, invalid int, result *int) (err error)
- func (this *Section) GetValidIt(key string, value *any) (err error)
- func (this *Section) GetValidPath(key string, result *string) (err error)
- func (this *Section) Len() int
- func (this *Section) Log()
- func (this *Section) NameContext(key string)
- func (this *Section) NewChild(it any) (rv *Section, err error)
- func (this *Section) OnlyKeys(allowedKeys ...string) (err error)
- func (this *Section) Prop(key string) string
- func (this *Section) Props() map[string]string
- func (this *Section) StructFromYaml(file string, target any) error
- func (this *Section) ToYaml(file string) error
- func (this *Section) WarnExtraKeys(allowedKeys ...string)
- func (this *Section) WarnUnknown(h *Help)
- func (this *Section) Watch(period time.Duration, onChange func(changedFile string) (done bool), ...)
- type StringValidator
- func StringBlank() StringValidator
- func StringBlankOr(validator StringValidator) StringValidator
- func StringHostOrIp() StringValidator
- func StringIp() StringValidator
- func StringLen(min, max int) StringValidator
- func StringMatch(re *regexp.Regexp) StringValidator
- func StringNotBlank() StringValidator
- func StringOneOf(choices ...string) StringValidator
- func StringOr(one, other StringValidator) StringValidator
- func ValidHostPort() StringValidator
- func ValidHttpUrl() StringValidator
- func ValidUrl(scheme ...string) StringValidator
- type UInt
- type UIntValidator
- type Visitor
- type Watch
Constants ¶
const ( PROPS = "properties" MaxUint = ^uint(0) MaxInt = int(MaxUint >> 1) MinInt = -MaxInt - 1 )
const ( ErrStringBlank = uerr.Const("String value empty") ErrStringNotBlank = uerr.Const("String value not empty") )
Variables ¶
var ( ThisHost = "" ThisIp = "" ThisProcess = "" // set by boot LocalAddrs = make(map[string]bool) ThisD = "" InitD = initInitD() // initial dir upon exec InstallD = initInstallD() // where we're installed DryRun = false )
Functions ¶
func Assign ¶
make sure types are assignable, then assign
var it any ... var toMap map[string]bool err := Assign( "context", &toMap, it )
func EnsureAddr ¶
Ensure addr is correctly filled in with default host/port if missing.
addr may be any of these:
HOST:PORT "" : HOST HOST: :PORT [HOST]:PORT [IPv6]:PORT
HOST may be an IP (v4 or v6), hostname, or fqdn.
The square brackets can only be used when PORT is also provided. And they must be used when HOST is an IPv6 address.
func Float64FromBitRateString ¶
convert a string to an float64 bit rate, taking into account SI prefixes: K, M, G, T, P: base 1000 multipliers
func Float64FromByteSizeString ¶
convert a string to an float64 byte size, taking into account SI prefixes: K, M, G, T, P: treat as base 1024 multipliers Ki, Mi, Gi, Ti, Pi: base 1024 multipliers
func Float64FromSiString ¶
convert a string to an float64, taking into account SI prefixes: K, M, G, T, P: base 1000 multipliers Ki, Mi, Gi, Ti, Pi: base 1024 multipliers
func IntFromBitRateString ¶
convert a string to an int64 bit rate, taking into account SI prefixes: K, M, G, T, P: base 1000 multipliers
also handled: - if string begins with "0x", then it is hex - if string begins with "0", then it is octal
func IntFromByteSizeString ¶
convert a string to an int64 byte size, taking into account SI prefixes: K, M, G, T, P: treat as base 1024 multipliers Ki, Mi, Gi, Ti, Pi: base 1024 multipliers
also handled: - if string begins with "0x", then it is hex - if string begins with "0", then it is octal
func IntFromSiString ¶
convert a string to an int64, taking into account SI prefixes: K, M, G, T, P: base 1000 multipliers Ki, Mi, Gi, Ti, Pi: base 1024 multipliers
also handled: - if string begins with "0x", then it is hex - if string begins with "0", then it is octal
func IsLocalUrl ¶
func IsThisHost ¶
is the specified host a known hostname or IP of the host we're running on?
func UIntFromBitRateString ¶
convert a string to an uint64 bit rate, taking into account SI prefixes: K, M, G, T, P: base 1000 multipliers
also handled: - if string begins with "0x", then it is hex - if string begins with "0", then it is octal
func UIntFromByteSizeString ¶
convert a string to an uint64 byte size, taking into account SI prefixes: K, M, G, T, P: treat as base 1024 multipliers Ki, Mi, Gi, Ti, Pi: base 1024 multipliers
also handled: - if string begins with "0x", then it is hex - if string begins with "0", then it is octal
func UIntFromSiString ¶
convert a string to an uint64, taking into account SI prefixes: K, M, G, T, P: base 1000 multipliers Ki, Mi, Gi, Ti, Pi: base 1024 multipliers
also handled: - if string begins with "0x", then it is hex - if string begins with "0", then it is octal
func ValidHostname ¶
check with net.ParseIP first to rule out if it is an IP addr
Types ¶
type Array ¶
type Array struct { Context string // contains filtered or unexported fields }
an array of config sections
func ArrayFromSection ¶
type Builder ¶
Builder works with Chain.Build, Chain.BuildIf, Chain.BuildFrom to build rv from config.
type Chain ¶
Chain provides a nicer means of accessing a config Section.
Chain allows chaining of accessor functions to avoid error checking boilerplate.
The accessor functions enable accessing the config settings and sub-sections.
The accessors also perform sensible type coercion. For example, if a setting is a string, but it is being accessed as an int, then it will be converted to an int if possible.
Validation funcs are also provided, or you can make your own.
A Section is usually provided to you in the golum lifecycle methods for creating or reloading your component. It is simple to convert it to a Chain.
var s *uconfig.Section var foo, bar, baz int err = s.Chain(). GetInt("foo", &foo). GetInt("bar", &bar, uconfig.MustBePos). GetInt("baz", &baz, uconfig.ValidRange(5, 20)). Each("array", func(c *Chain) (err error) { return c. ... Done() } Done()
func (*Chain) ASection ¶
deprecated - use Must().
get the sub-section specified by key and process it
func (*Chain) Build ¶
build value from current config section using builder
if builder returns nil, then no assignment is made to value
value is typically a pointer to the thing that will be built. If the thing to be built is a pointer, then it must be the addres of the pointer.
func (*Chain) BuildFrom ¶
build value from named config section
if builder returns nil, then no assignment is made to value
value is typically a pointer to the thing that will be built. If the thing to be built is a pointer, then it must be the addres of the pointer.
func (*Chain) BuildIf ¶
build value from named config section if it exists
if builder returns nil, then no assignment is made to value
value is typically a pointer to the thing that will be built. If the thing to be built is a pointer, then it must be the addres of the pointer.
func (*Chain) Construct ¶
func (this *Chain) Construct(target Constructable) *Chain
Construct target from current config section.
func (*Chain) ConstructFrom ¶
func (this *Chain) ConstructFrom(key string, target Constructable) *Chain
Construct target from named config sub-section.
func (*Chain) ConstructIf ¶
func (this *Chain) ConstructIf(key string, target Constructable) *Chain
Construct target from named config sub-section if sub-section exists.
func (*Chain) Done ¶
end the accessor chain, detecting invalid config, returning active error (if any)
func (*Chain) Each ¶
func (this *Chain) Each(key string, builder ChainVisitor) *Chain
run builder against each sub section in named array
func (*Chain) EachIf ¶
func (this *Chain) EachIf(key string, builder ChainVisitor) *Chain
run builder against each sub section in named array, if array exists
func (*Chain) EachSection ¶
deprecated - use Each().
get the array specified by key and iterate through the contained sections
func (*Chain) EachSectionIf ¶
deprecated - use EachIf().
get the array specified by key if it exists and iterate through the sections.
func (*Chain) FailExtraKeys ¶
func (*Chain) GetArrayIf ¶
prefer EachIf()
func (*Chain) GetBitRate ¶
func (this *Chain) GetBitRate( key string, result any, validators ...IntValidator, ) *Chain
func (*Chain) GetByteSize ¶
func (this *Chain) GetByteSize( key string, result any, validators ...IntValidator, ) *Chain
func (*Chain) GetCreateDir ¶
func (*Chain) GetFloat64 ¶
func (this *Chain) GetFloat64( key string, value *float64, validators ...FloatValidator, ) *Chain
func (*Chain) GetInt ¶
func (this *Chain) GetInt( key string, result any, validators ...IntValidator, ) *Chain
func (*Chain) GetInts ¶
func (this *Chain) GetInts( key string, result *[]int, validators ...IntValidator, ) *Chain
func (*Chain) GetMillis ¶
func (this *Chain) GetMillis(key string, value *int64, validators ...IntValidator, ) *Chain
func (*Chain) GetRawString ¶
func (this *Chain) GetRawString( key string, result *string, validators ...StringValidator, ) *Chain
get raw string value with no detemplating or translation
func (*Chain) GetRegexpIf ¶
func (*Chain) GetSection ¶
deprecated
func (*Chain) GetSectionIf ¶
deprecated
func (*Chain) GetString ¶
func (this *Chain) GetString( key string, result *string, validators ...StringValidator, ) *Chain
if key resolves to string, then set result
func (*Chain) GetStringMap ¶
if key resolves to map[string]string, then set value
func (*Chain) GetStrings ¶
func (this *Chain) GetStrings( key string, result *[]string, validators ...StringValidator, ) *Chain
if key resolves to []string, then set result
func (*Chain) GetUInt ¶
func (this *Chain) GetUInt( key string, result any, validators ...UIntValidator, ) *Chain
func (*Chain) GetValidInt ¶
func (*Chain) GetValidIt ¶
if key resolves to some value, then set value, otherwise error
func (*Chain) If ¶
func (this *Chain) If(key string, builder ChainVisitor) *Chain
run builder with specified sub-section if section exists
func (*Chain) IfHasKeysIn ¶
func (this *Chain) IfHasKeysIn(f ChainVisitor, keys ...string) *Chain
if any of the keys are present, call handler
func (*Chain) IfHasKeysMatching ¶
func (this *Chain) IfHasKeysMatching(f ChainVisitor, r *regexp.Regexp) *Chain
if any of the keys are present, call handler
func (*Chain) Must ¶
func (this *Chain) Must(key string, builder ChainVisitor) *Chain
run builder with specified sub-section if section exists, fail otherwise
func (*Chain) WarnExtraKeys ¶
type ChainVisitor ¶
ChainVisitor works with Chain.If, Chain.Must, Chain.Each.
type Constructable ¶
Constructable works with Chain.Construct, Chain.ConstructFrom, Chain.ConstructIf for things that construct themselves from config.
type FloatValidator ¶
use with Section.GetFloat64, Chain.GetFloat64 to validate float
func FloatRange ¶
func FloatRange(min, max float64) FloatValidator
return a range validator for GetInt
type Help ¶
type Help yaml.MapSlice
accumulates ordered help info - see golum.Show
func (*Help) SetDefault ¶
Set default value for this
type IntValidator ¶
use with Section.GetInt, Chain.GetInt to validate signed int
func IntAtLeast ¶
func IntAtLeast(min int64) IntValidator
return a validator to error if v not at least min
type Section ¶
type Section struct { Context string // contains filtered or unexported fields }
Section represents a config section, and allows access to the settings in the config.
Methods are provided for accessing settings. Many of these methods will perform type coercion. For example, if a setting is provided as a string but is being requested as an int, then the setting will be converted to an int if possible.
The newer Chain API is preferred over this one. To convert a Section to a Chain:
var s *uconfig.Section chain := s.Chain()...
A Section will typically be provided by the golum lifecycle methods to you, so you don't have to create one in 99% of the cases.
func NewSection ¶
create a new Section from nil, /path/to/yaml/file, YAML string, YAML []byte, map[string]any, or map[string]string
func (*Section) AnyKeysMatch ¶
return true if any of the keys match
func (*Section) AsResolvedMap ¶
dump out the config section as a map, resolving all properties
func (*Section) CloneProps ¶
get a copy of the property map
func (*Section) DiffersFrom ¶
compare this section to another one
func (*Section) EachString ¶
iterate through config items in section, aborting if visitor returns error
func (*Section) FailExtraKeys ¶
fail if any other keys are specified in the section than have already been acessed or (if provided) specified in allowedKeys
func (*Section) GetArrayIf ¶
if key is a Array, set result to it
func (*Section) GetBitRate ¶
func (this *Section) GetBitRate( key string, result any, validators ...IntValidator, ) (err error)
if found, update result with bit rate
SI suffixes such as K, M, G are supported, but Ki, Mi, etc are not.
result must be the address of some sort of signed int.
zero or more validators may be supplied. they take the converted value as an int64. this func will perform basic range checking based on the size of the int after validators are run
handles strings with 0x (hex) or 0 (octal) prefixes
func (*Section) GetByteSize ¶
func (this *Section) GetByteSize( key string, result any, validators ...IntValidator, ) (err error)
if found, update result with byte size.
SI suffixes such as K, M, G will be interpreted the same as Ki, Mi, Gi.
result must be the address of some sort of signed int.
zero or more validators may be supplied. they take the converted value as an int64. this func will perform basic range checking based on the size of the int after validators are run
handles strings with 0x (hex) or 0 (octal) prefixes
func (*Section) GetCreateDir ¶
Same as GetPath, but also ensures directory exists, creating it if necessary
func (*Section) GetDuration ¶
if found, parse to duration and update val
func (*Section) GetFloat64 ¶
func (this *Section) GetFloat64( key string, val *float64, validators ...FloatValidator, ) (err error)
if found, parse to float64 and update val
func (*Section) GetInt ¶
func (this *Section) GetInt( key string, result any, validators ...IntValidator, ) (err error)
if found, update result with integral value.
result must be the address of some sort of signed int.
SI suffixes of K, M, G, T are base 1000 multipliers.
SI suffixes of Ki, Mi, Gi, Ti are base 1024 multipliers.
zero or more validators may be supplied. they take the converted value as an int64. this func will perform basic range checking based on the size of the int after validators are run
handles strings with 0x (hex) or 0 (octal) prefixes
func (*Section) GetInts ¶
func (this *Section) GetInts( key string, result *[]int, validators ...IntValidator, ) (err error)
if found, parse into []int and update val
func (*Section) GetMillis ¶
func (this *Section) GetMillis( key string, val *int64, validators ...IntValidator, ) ( err error, )
if found, parse to duration as millis and update val
func (*Section) GetPath ¶
if value is found and a string, then set result to absolute path of value.
otherwise, if value is found but not a string or is blank, then error
func (*Section) GetRawString ¶
func (this *Section) GetRawString( key string, result *string, validators ...StringValidator, ) (err error)
if found, parse to string and set result without detemplatizing
func (*Section) GetRegexpIf ¶
if found and not blank, parse to regexp and set result
func (*Section) GetSection ¶
Get the section or error if it does not exist or is invalid
func (*Section) GetSectionIf ¶
if key maps to a sub-section, set val to it
func (*Section) GetString ¶
func (this *Section) GetString( key string, result *string, validators ...StringValidator, ) (err error)
if found, parse to string and set result, resolving any templating
func (*Section) GetStringMap ¶
if found, parse into map[string]string and update val
func (*Section) GetStrings ¶
func (this *Section) GetStrings( key string, result *[]string, validators ...StringValidator, ) (err error)
if found, parse into []string and update val
func (*Section) GetStruct ¶
Get (using JSON conversion) the specified section into dst (a &struct). If key not found, dst is unmodified. May not be super performant, but ok for config type stuff.
func (*Section) GetUInt ¶
func (this *Section) GetUInt( key string, result any, validators ...UIntValidator, ) (err error)
if found, update result with unsigned integral value
result must be the address of some sort of unsigned int
zero or more validators may be supplied. they take the converted value as a uint64. this func will perform basic range checking based on the size of the int after validators are run
handles strings with 0x (hex) or 0 (octal) prefixes handles strings with SI suffixes (G, M, K, Gi, Mi, Ki, ...)
func (*Section) GetUrl ¶
func (this *Section) GetUrl( key string, result **nurl.URL, validators ...StringValidator, ) (err error)
get and parse the url, setting result
func (*Section) GetUrlIf ¶
func (this *Section) GetUrlIf( key string, result **nurl.URL, validators ...StringValidator, ) (err error)
if found and not blank, parse to url and set result
func (*Section) GetValidInt ¶
same as GetInt, but error if result == invalid
func (*Section) GetValidPath ¶
same as GetPath, except also errors if unable to stat path
func (*Section) NameContext ¶
func (*Section) NewChild ¶
create a new Section as a child of this one from nil, /path/to/yaml/file, YAML string, YAML []byte, map[string]any, or map[string]string
func (*Section) OnlyKeys ¶
return error if any other keys are specfied in the section than what have already been accessed or (if provided) specified in allowedKeys
func (*Section) StructFromYaml ¶
read in the specified yaml file, performing properties on the text, then unmarshal it into target (a ptr to struct)
func (*Section) WarnExtraKeys ¶
issue a warning if any other keys are specified in the section than have already been acessed or (if provided) specified in allowedKeys
func (*Section) WarnUnknown ¶
issue warnings for any undocumented parameters
type StringValidator ¶
use with Section.GetString, Chain.GetString to validate string
func StringBlankOr ¶
func StringBlankOr(validator StringValidator) StringValidator
create a StringValidator to verify value is blank or valid
func StringHostOrIp ¶
func StringHostOrIp() StringValidator
create a StringValidator to verify value is an IP or hostname
func StringLen ¶
func StringLen(min, max int) StringValidator
a StringValidator to verify string length
func StringMatch ¶
func StringMatch(re *regexp.Regexp) StringValidator
a StringValidator to verify string matches regular expression
func StringNotBlank ¶
func StringNotBlank() StringValidator
a StringValidator to verify string not blank
func StringOneOf ¶
func StringOneOf(choices ...string) StringValidator
create a StringValidator to verify value is one of listed
func StringOr ¶
func StringOr(one, other StringValidator) StringValidator
either one or other must be true
func ValidHostPort ¶
func ValidHostPort() StringValidator
return a StringValidator to ensure valid host:port
func ValidHttpUrl ¶
func ValidHttpUrl() StringValidator
return a StringValidator to ensure valid http or https URL
func ValidUrl ¶
func ValidUrl(scheme ...string) StringValidator
return a StringValidator to ensure valid URL with a valid scheme
type UIntValidator ¶
use with Section.GetUInt, Chain.GetUInt to validate unsigned int
type Visitor ¶
Use with Chain.EachSection, Chain.EachSectionIf, Chain.ASection, Chain.IfSection, Array.Each
type Watch ¶
type Watch struct {
// contains filtered or unexported fields
}
used to watch for changes to files
func (*Watch) Start ¶
func (this *Watch) Start( period time.Duration, onChange func(changedFile string) (done bool), onError func(err error) (done bool), )
watch files. if there is a change, then call onChange. if there is an error and onError is set, then call it.
if either func returns true, then watching will be stopped