vtypes

package module
v0.0.0-...-575d002 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2025 License: MIT Imports: 8 Imported by: 5

Documentation

Overview

Package vtypes provides value type handling helpers and types.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTypeUnsupported  = errors.New("type unsupported")
	ErrValueUnsupported = errors.New("value unsupported")
)

Functions

func ConvertCompatible

func ConvertCompatible(val any) any

ConvertCompatible wraps compatible types.

func DefaultValueText

func DefaultValueText(val any) string

DefaultValueText returns a "best effort" text representation of the value. Explicit values are communicated by types implementing DefaultValueTexter.

func Hydrate

func Hydrate(val any, raw string) error

Hydrate will parse the raw string value and use the result to update val. Valid val type values are:

func ValueTypeName

func ValueTypeName(val any) string

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 Error

type Error struct {
	// contains filtered or unexported fields
}

func NewError

func NewError(child error) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Is

func (e *Error) Is(err error) bool

func (*Error) Unwrap

func (e *Error) Unwrap() error

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

type OnSetBoolFunc func(bool) error

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

type OnSetFunc func(string) error

OnSetFunc is an implementation of OnSetter.

func (OnSetFunc) IsBool

func (f OnSetFunc) IsBool() bool

IsBool indicates whether the receiver function is intended to handle bool values.

func (OnSetFunc) OnSet

func (f OnSetFunc) OnSet(val string) error

OnSet calls the receiver function.

type OnSetter

type OnSetter interface {
	OnSet(val string) error
	IsBool() bool
}

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 MakeSlice

func MakeSlice(ptrValue any) Slice

MakeSlice returns an instance of Slice.

func (*Slice) IsBool

func (s *Slice) IsBool() bool

IsBool indicates whether the underlying slice element type is bool.

func (*Slice) MarshalText

func (s *Slice) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*Slice) UnmarshalText

func (s *Slice) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (*Slice) Value

func (s *Slice) Value() any

Value returns the original value with its pointer chain.

func (*Slice) ValueTypeName

func (s *Slice) ValueTypeName() string

ValueTypeName returns the name of the underlying slice element type, adding information if unmarshaling is configured to handle a set of values.

type StringSetter

type StringSetter interface {
	Set(val string) error
	fmt.Stringer
}

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
}

Jump to

Keyboard shortcuts

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