Documentation
¶
Overview ¶
Package vtypes provides value type handling helpers and types.
Index ¶
- Variables
- func ConvertCompatible(val any) any
- func DefaultValueText(val any) string
- func Hydrate(val any, raw string) error
- func ValueTypeName(val any) string
- type DefaultValueTexter
- type Error
- type HydrateError
- type OnSetBoolFunc
- type OnSetFunc
- type OnSetter
- type Slice
- type StringSetter
- type TextMarshalUnmarshaler
- type ValueTypeNamer
Constants ¶
This section is empty.
Variables ¶
var ( ErrTypeUnsupported = errors.New("type unsupported") ErrValueUnsupported = errors.New("value unsupported") )
Functions ¶
func ConvertCompatible ¶
ConvertCompatible wraps compatible types.
func DefaultValueText ¶
DefaultValueText returns a "best effort" text representation of the value. Explicit values are communicated by types implementing DefaultValueTexter.
func Hydrate ¶
Hydrate will parse the raw string value and use the result to update val. Valid val type values are:
- builtin: *string, *bool, error, *int, *int8, *int16, *int32, *int64, *uint, *uint8, *uint16, *uint32, *uint64, *float32, *float64
- stdlib: *time.Duration, flag.Value
- vtypes: TextMarshalUnmarshaler, OnSetter, StringSetter, OnSetFunc, OnSetBoolFunc
func ValueTypeName ¶
ValueTypeName returns a "best effort" text representation of the value's type name. Explicit values are communicated by types implementing ValueTypeNamer.
Types ¶
type DefaultValueTexter ¶
type DefaultValueTexter interface {
DefaultValueText() string
}
type HydrateError ¶
type HydrateError struct {
Val any
// contains filtered or unexported fields
}
func NewHydrateError ¶
func NewHydrateError(child error, val any) *HydrateError
func (*HydrateError) Error ¶
func (e *HydrateError) Error() string
func (*HydrateError) Is ¶
func (e *HydrateError) Is(err error) bool
func (*HydrateError) Unwrap ¶
func (e *HydrateError) Unwrap() error
type OnSetBoolFunc ¶
OnSetBoolFunc is an implementation of OnSetter.
func (OnSetBoolFunc) IsBool ¶
func (f OnSetBoolFunc) IsBool() bool
IsBool indicates whether the receiver function is intended to handle bool values.
func (OnSetBoolFunc) OnSet ¶
func (f OnSetBoolFunc) OnSet(s string) error
OnSet calls the receiver function, first parsing the string value as a bool type.
type OnSetFunc ¶
OnSetFunc is an implementation of OnSetter.
type OnSetter ¶
OnSetter describes types that will have a callback (OnSet) run when hydrated. The IsBool method conveys type information used to determine the default text and can be used to inform external handlers.
type Slice ¶
type Slice struct {
TypeName string
SplitEach bool
Separator string
NonAccum bool
// contains filtered or unexported fields
}
Slice is an implementation of TextMarshalUnmarshaler that wraps a slice value (possibly with multiple levels of pointers) of any type supported by Hydrate. Behavior can be configured to treat each UnmarshalText call as a set of values. The underlying slice is only initialized if values are added; otherwise, nil pointers in the chain remain nil.
func (*Slice) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Slice) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
func (*Slice) ValueTypeName ¶
ValueTypeName returns the name of the underlying slice element type, adding information if unmarshaling is configured to handle a set of values.
type StringSetter ¶
StringSetter describes types that are set by and expressed as a string value.
type TextMarshalUnmarshaler ¶
type TextMarshalUnmarshaler interface {
encoding.TextUnmarshaler
encoding.TextMarshaler
}
TextMarshalUnmarshaler descibes types that are able to be marshaled to and unmarshaled from text.
type ValueTypeNamer ¶
type ValueTypeNamer interface {
ValueTypeName() string
}