Documentation
¶
Index ¶
- Constants
- func Copy(dst, src any) error
- func Get(s any, h GetHandler)
- func GetAsMap(s any, h GetHandler, opts *MapOpts) map[string]any
- func GetAsSlice(s any, h GetHandler, opts *SliceOpts) []any
- func GetFloat64(a any) (float64, error)
- func Set(r SetRequest, dst any) error
- func SetJson(src, dst reflect.Value) error
- type Chain
- type FilterMapOpts
- type GetHandler
- type MapOpts
- type Mapper
- type SetFunc
- type SetRequest
- type SliceOpts
- type Slicer
Constants ¶
const ( FuzzyFloats = 1 << iota FuzzyInts FuzzyStrings Fuzzy = FuzzyFloats | FuzzyInts | FuzzyStrings )
Variables ¶
This section is empty.
Functions ¶
func Copy ¶
Copy sets all fields in dst to any fields in src with the same name. It is a convenience and small optimization over using Set(). WIP: Currently just a simple struct-to-struct top-level copy. Additional details will be added as needed.
func Get ¶
func Get(s any, h GetHandler)
Get iterates the fields in a struct, sending the results to a handler.
func GetAsMap ¶
func GetAsMap(s any, h GetHandler, opts *MapOpts) map[string]any
GetAsMap iterates the fields in a struct, adding the results to a map based on a handler and returning the map. The handler can be a chain. The final element of the chain must be a Mapper, but you don't need to include it: If the chain doesn't end in a Mapper, then one will be added and provided the MapOpts.
func GetAsSlice ¶
func GetAsSlice(s any, h GetHandler, opts *SliceOpts) []any
GetAsSlice iterates the fields in a struct, adding the results to a slice based on a handler and returning the slice. The handler can be a chain. The final element of the chain must be a Slicer, but you don't need to include it: If the chain doesn't end in a Slicer, then one will be added and provided the SliceOpts.
func GetFloat64 ¶
func Set ¶
func Set(r SetRequest, dst any) error
Set sets the value of each field to the supplied value.
Types ¶
type Chain ¶
type Chain []GetHandler
func NewChain ¶
NewChain takes a list of items and converts them into handlers, answering the new handler Chain. Items can be: * A Handler. It is added directly to the chain. * An *Opts (SlicerOpts, etc.). It is converted to the associated Handler and added to the chain. * A map[string]string. It is converted to a FilterMap Handler.
type FilterMapOpts ¶
type GetHandler ¶
type GetHandler interface { // Handle the pair in some fashion, returning the (potentially // changed, filtered etc. data). The basic system // is designed to work without errors; if a client needs // any error handling, it should track that in an internal state. Handle(name string, value any) (string, any) }
GetHandler is used to get name/value pairs from a struct.
func FilterMap ¶
func FilterMap(opts FilterMapOpts) GetHandler
func Map ¶
func Map(opts MapOpts) GetHandler
func Slice ¶
func Slice(opts SliceOpts) GetHandler
type SetRequest ¶
type SetRequest struct { FieldNames []string NewValues []any Assigns []SetFunc // Optional: Provide assignment func for each value. Nil will use default. Flags uint8 }
func SetRequestFrom ¶
func SetRequestFrom(m map[string]any) SetRequest
func (SetRequest) Validate ¶
func (r SetRequest) Validate() error