Documentation
¶
Overview ¶
Package shared provides functions shared by generated code.
Index ¶
- Variables
- func DefaultValue(defaultValue string, hasDefaultValue bool) *string
- func IsSupportedType(typ structure.TypeBase) (isSupported bool, parserName string)
- func LoadSlice[T any](c *LoadContext, v *core.Viper, l Loader[T]) ([]T, core.Facts, error)
- func Parse[T any](c *LoadContext, value, defaultValue *string, p Parser[T]) (result T, facts core.Facts, err error)
- func ParseBool(s string) (bool, error)
- func ParseSlice[T any](c *LoadContext, v *core.Viper, key string, p Parser[T]) ([]T, core.Facts, error)
- func ViperSub(v *core.Viper, configKey string, hasConfigKey bool) *core.Viper
- type LoadContext
- type Loader
- type Parser
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ParseString is Parser[string]. ParseString = wrap(cast.ToStringE) // ParseInt is Parser[int]. ParseInt = wrap(cast.ToIntE) // ParseInt8 is Parser[int8]. ParseInt8 = wrap(cast.ToInt8E) // ParseInt16 is Parser[int16]. ParseInt16 = wrap(cast.ToInt16E) // ParseInt32 is Parser[int32]. ParseInt32 = wrap(cast.ToInt32E) // ParseInt64 is Parser[int64]. ParseInt64 = wrap(cast.ToInt64E) // ParseUint is Parser[uint]. ParseUint = wrap(cast.ToUintE) // ParseUint8 is Parser[uint8]. ParseUint8 = wrap(cast.ToUint8E) // ParseUint16 is Parser[uint16]. ParseUint16 = wrap(cast.ToUint16E) // ParseUint32 is Parser[uint32]. ParseUint32 = wrap(cast.ToUint32E) // ParseUint64 is Parser[uint64]. ParseUint64 = wrap(cast.ToUint64E) // ParseFloat32 is Parser[float32]. ParseFloat32 = wrap(cast.ToFloat32E) // ParseFloat64 is Parser[float64]. ParseFloat64 = wrap(cast.ToFloat64E) // ParseDuration is Parser[time.Duration]. ParseDuration = wrap(cast.ToDurationE) )
Functions ¶
func DefaultValue ¶
DefaultValue returns the default value as a pointer if it's set.
func IsSupportedType ¶
IsSupportedType checks if there is a parser for the given type.
func Parse ¶
func Parse[T any](c *LoadContext, value, defaultValue *string, p Parser[T]) (result T, facts core.Facts, err error)
Parse parsers a config value with the given parser.
func ParseBool ¶
ParseBool is Parser[bool].
Also, can parse YAML-specific bool representation, i.e., yes/no, on/off.
Types ¶
type LoadContext ¶
type LoadContext struct {
Keys []string
}
LoadContext tracks the path when reading nested config values.
func ContextWithKey ¶
func ContextWithKey(c *LoadContext, key string, hasKey bool) *LoadContext
ContextWithKey adds the config key to the context if provided.
func (*LoadContext) WithIndex ¶
func (c *LoadContext) WithIndex(index uint64) *LoadContext
WithIndex adds an array index to the context.
func (*LoadContext) WithKey ¶
func (c *LoadContext) WithKey(key string) *LoadContext
WithKey adds a key to the context.
Click to show internal directories.
Click to hide internal directories.