pick

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: MIT Imports: 14 Imported by: 0

README

Pick

CI Status codecov Go Report Card PkgGoDev

Pick is a go package to access (using dot and array notation) and convert any kind of data, using best effort performance and best effort convert. It is an alternative to stretchr/objx aiming to provide three main things:

  1. Modular approach regarding the converter, traverser and selector format
  2. Best effort performance using reflect as last resort.
  3. Best effort convert aiming to cast and convert between types as much as possible.

Install

go get -u github.com/moukoublen/pick

Examples

j := `{
    "item": {
        "one": 1,
        "two": "ok",
        "three": ["element 1", 2, "element 3"]
    },
    "float": 2.12,
    "floatDec": 2
}`

p1, _ := WrapJSON([]byte(j))
got, err := p1.String("item.three[1]")  // "2", nil
got, err := p1.Uint64("item.three[1]")  // uint64(2), nil
got, err := p1.String("item.three[-1]") // "element 3", nil | (access the last element)element
got, err := p1.Float32("float")         // float32(2.12), nil
got, err := p1.Int64("float")           // int64(2), ErrConvertLostDecimals
got, err := p1.Int64("floatDec")        // int64(2), nil
got, err := p1.Int32("non-existing")    // 0, ErrFieldNotFound

// Relaxed API (no error in return)
got := p1.Relaxed().Int32("item.one")  // int32(1)
got := p1.Relaxed().Int32("none")      // int32(0)

// Relaxed with errors sink
sink := ErrorsSink{}
sm2 := p1.Relaxed(&sink)
got := sm2.String("item.three[1]") // "2"
got := sm2.Uint64("item.three[1]") // uint64(2)
got := sm2.Int32("item.one")       // int32(1)
got := sm2.Float32("float")        // float32(2.12)
got := sm2.Int64("float")          // int64(2) | error lost decimals
got := sm2.String("item.three")    // ""       | error field not found
err := sink.Outcome()              // joined error
Generics functions
got, err := Get[int64](p1, "item.three[1]")  // (int64(2), nil)
got, err := Get[string](p1, "item.three[1]") // ("2", nil)

m := p1.Relaxed()
got := RelaxedGet[string](m, "item.three[1]") // "2"

got, err := Path[string](p1, Field("item"), Field("three"), Index(1)) // ("2", nil)
got := RelaxedPath[float32](m, Field("item"), Field("one")          // float32(1)
Map functions
j2 := `{
    "items": [
        {"id": 34, "name": "test1", "array": [1,2,3]},
        {"id": 35, "name": "test2", "array": [4,5,6]},
        {"id": 36, "name": "test3", "array": [7,8,9]}
    ]
}`
p2, _ := WrapJSON([]byte(j2))

got, err := Map(p2, "items", func(p Picker) (int16, error) {
    n, _ := p.Int16("id")
    return n, nil
}) // ( []int16{34, 35, 36}, nil )

got, err := FlatMap(p2, "items", func(p Picker) ([]int16, error) {
    return p.Int16Slice("array")
}) // ( []int16{1, 2, 3, 4, 5, 6, 7, 8, 9}, nil )

got3, err3 := MapFilter(p2, "items", func(p Picker) (int32, bool, error) {
    i, err := p.Int32("id")
    return i, i%2 == 0, err
}) // ( []int32{34, 36}, nil )
Each/EachField functions
j := `{
    "2023-01-01": [1,2,3],
    "2023-01-02": [1,2,3,4],
    "2023-01-03": [1,2,3,4,5]
}`
p, _ := WrapJSON([]byte(j))

lens := map[string]int{}
err := EachField(p, "", func(field string, value Picker, numOfFields int) error {
    l, _ := value.Len("")
    lens[field] = l
    return nil
}) // nil
// lens == map[string]int{"2023-01-01": 3, "2023-01-02": 4, "2023-01-03": 5})


sumEvenIndex := 0
err = Each(p, "2023-01-03", func(index int, item Picker, totalLength int) error {
    if index%2 == 0 {
        sumEvenIndex += item.Relaxed().Int("")
    }
    return nil
}) // nil
// sumEvenIndex == 6
API

As an API we define a set of functions like this Bool(T) Output for all basic types. There are 2 different APIs for a picker.

  • Default API, the default one that is embedded in Picker.
    E.g. Picker.Bool(selector string) (bool, error)
  • Relaxed API that can be accessed by calling Picker.Relaxed().
    E.g. Picker.Relaxed().Bool(selector string) bool. Relaxed API does not return error neither it panics in case of one. It just ignores any possible error and returns the default zero value in case of one. Errors can be optionally gathered using an ErrorGatherer.

Supported Types in API

  • bool / []bool
  • byte / []byte
  • float{32,64} / []float{32,64}
  • int{,8,16,32,64} / []int{,8,16,32,64}
  • uint{,8,16,32,64} / []uint{,8,16,32,64}
  • string / []string
  • time.Time / []time.Time
  • time.Duration / []time.Duration
Relaxed API
p1.Relaxed().String("item.three[1]") // == "2"
sm := p1.Relaxed()
sm.Uint64("item.three[1]") // == uint64(2)

Optionally an ErrorGatherer could be provided to .Relaxed() initializer to receive and handle each error produced by the operations.

A default implementation of ErrorGatherer is the ErrorsSink, which gathers all errors into a single one.


Pick is currently in a alpha stage, a lot of changes going to happen both to api and structure.

More technical details about pick internals, in architecture documentation.


Acknowledgements

Special thanks to Konstantinos Pittas (@kostaspt) for helping me ... pick the name of the library.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCannotConvertToBasic = errors.New("value cannot be converted to basic type")
	ErrAlreadyBasicType     = errors.New("value is already basic type")
)
View Source
var (
	ErrConvertOverFlow      = errors.New("overflow error")
	ErrConvertLostDecimals  = errors.New("missing decimals error")
	ErrConvertInvalidType   = errors.New("invalid type")
	ErrConvertInvalidSyntax = errors.New("invalid syntax")
)
View Source
var (
	ErrInvalidSelectorFormatForName  = errors.New("invalid format for name key")
	ErrInvalidSelectorFormatForIndex = errors.New("invalid format for index key")
	ErrInvalidSelectorFormat         = errors.New("invalid selector format")
)
View Source
var (
	ErrFieldNotFound   = errors.New("field not found")
	ErrIndexOutOfRange = fmt.Errorf("%w: index out of range", ErrFieldNotFound)
	ErrKeyConvert      = errors.New("key convert error")
	ErrKeyUnknown      = errors.New("key type unknown")
)
View Source
var ErrTimeConvertConfig = errors.New("invalid time converter config")

Functions

func Convert added in v0.2.0

func Convert[Output any](input any) (Output, error)

Convert attempts to convert the input value to the specified (generic) Output type. It returns the converted value of type Output and an error if the converting fails. e.g.

Convert[string](123) // "123", nil

func Each

func Each(p Picker, selector string, operation func(index int, item Picker, totalLength int) error) error

Each iterates over all elements selected by the given selector and applies the provided operation function to each element. It returns An error if any step in the selection or operation process fails, otherwise nil.

func EachField added in v0.1.0

func EachField(p Picker, selector string, operation func(field string, value Picker, numOfFields int) error) error

EachField iterates over all fields of the object selected by the given selector and applies the provided operation function to each field's value. It returns An error if any step in the selection or operation process fails, otherwise nil.

func FlatMap

func FlatMap[Output any](p Picker, selector string, transform func(Picker) ([]Output, error)) ([]Output, error)

func Get

func Get[Output any](p Picker, selector string) (Output, error)

Get parses the selector, traverses with the provided path and if found, it resolves the convert type from the generic type.

func Map

func Map[Output any](p Picker, selector string, transform func(Picker) (Output, error)) ([]Output, error)

func MapFilter

func MapFilter[Output any](p Picker, selector string, transform func(Picker) (Output, bool, error)) ([]Output, error)

func OrDefault

func OrDefault[Output any](p Picker, selector string, defaultValue Output) (Output, error)

OrDefault will return the default value if any error occurs. If the error is ErrFieldNotFound the error will not be returned.

func Path

func Path[Output any](p Picker, path ...Key) (Output, error)

Path traverses with the provided path and if found, it resolves the convert type from the generic type.

func RelaxedEach added in v0.2.0

func RelaxedEach(a RelaxedAPI, selector string, operation func(index int, item RelaxedAPI, length int) error)

RelaxedEach applies operation function to each element of the given selector. The operation functions receives the index of the element, a SelectorRelaxedAPI and the total length of the slice (or 1 if input is a single element and not a slice).

func RelaxedEachField added in v0.2.0

func RelaxedEachField(a RelaxedAPI, selector string, operation func(field string, value RelaxedAPI, numOfFields int) error)

RelaxedEachField applies operation function to each field of the object of the given selector. The operation functions receives the name of the field of the element, a SelectorRelaxedAPI and the total length of the slice (or 1 if input is a single element and not a slice).

func RelaxedFlatMap added in v0.2.0

func RelaxedFlatMap[Output any](a RelaxedAPI, selector string, transform func(RelaxedAPI) ([]Output, error)) []Output

func RelaxedGet added in v0.2.0

func RelaxedGet[Output any](a RelaxedAPI, selector string) Output

RelaxedGet resolves the convert type from the generic type. Version of Get that uses SelectorRelaxedAPI.

func RelaxedMap added in v0.2.0

func RelaxedMap[Output any](a RelaxedAPI, selector string, transform func(RelaxedAPI) (Output, error)) []Output

RelaxedMap transform each element of a slice (or a the single element if selector leads to not slice) by applying the transform function. It also gathers any possible error of Relaxed API to `multipleError` and returns it. Example:

itemsSlice, err := RelaxedMap(p.Relaxed(), "near_earth_objects.2023-01-07", func(sm SelectorRelaxedAPI) Item {
	return Item{
		Name:   sm.String("name"),
		Sentry: sm.Bool("is_sentry_object"),
	}
})

func RelaxedMapFilter added in v0.2.0

func RelaxedMapFilter[Output any](a RelaxedAPI, selector string, transform func(RelaxedAPI) (Output, bool, error)) []Output

func RelaxedOrDefault added in v0.2.0

func RelaxedOrDefault[Output any](a RelaxedAPI, selector string, defaultValue Output) Output

RelaxedOrDefault will return the default value if any error occurs. Version of OrDefault that uses SelectorRelaxedAPI.

func RelaxedPath added in v0.2.0

func RelaxedPath[Output any](a RelaxedAPI, path ...Key) Output

RelaxedPath is the version of Path that uses SelectorRelaxedAPI.

Types

type ConvertError added in v0.2.0

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

func (*ConvertError) Error added in v0.2.0

func (c *ConvertError) Error() string

func (*ConvertError) Unwrap added in v0.2.0

func (c *ConvertError) Unwrap() error

type Converter added in v0.2.0

type Converter interface {
	As(input any, asKind reflect.Kind) (any, error)
	ByType(input any, asType reflect.Type) (any, error)
	// contains filtered or unexported methods
}

type DefaultConverter added in v0.2.0

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

func NewDefaultConverter added in v0.2.0

func NewDefaultConverter() DefaultConverter

func (DefaultConverter) As added in v0.2.0

func (c DefaultConverter) As(input any, asKind reflect.Kind) (any, error)

func (DefaultConverter) AsBool added in v0.2.0

func (c DefaultConverter) AsBool(input any) (bool, error)

func (DefaultConverter) AsBoolSlice added in v0.2.0

func (c DefaultConverter) AsBoolSlice(input any) ([]bool, error)

func (DefaultConverter) AsByte added in v0.2.0

func (c DefaultConverter) AsByte(input any) (byte, error)

func (DefaultConverter) AsByteSlice added in v0.2.0

func (c DefaultConverter) AsByteSlice(input any) ([]byte, error)

func (DefaultConverter) AsDuration added in v0.2.0

func (c DefaultConverter) AsDuration(input any) (time.Duration, error)

func (DefaultConverter) AsDurationSlice added in v0.2.0

func (c DefaultConverter) AsDurationSlice(input any) ([]time.Duration, error)

func (DefaultConverter) AsDurationSliceWithConfig added in v0.2.0

func (c DefaultConverter) AsDurationSliceWithConfig(config DurationConvertConfig, input any) ([]time.Duration, error)

func (DefaultConverter) AsDurationWithConfig added in v0.2.0

func (c DefaultConverter) AsDurationWithConfig(config DurationConvertConfig, input any) (time.Duration, error)

func (DefaultConverter) AsFloat32 added in v0.2.0

func (c DefaultConverter) AsFloat32(input any) (float32, error)

func (DefaultConverter) AsFloat32Slice added in v0.2.0

func (c DefaultConverter) AsFloat32Slice(input any) ([]float32, error)

func (DefaultConverter) AsFloat64 added in v0.2.0

func (c DefaultConverter) AsFloat64(input any) (float64, error)

func (DefaultConverter) AsFloat64Slice added in v0.2.0

func (c DefaultConverter) AsFloat64Slice(input any) ([]float64, error)

func (DefaultConverter) AsInt added in v0.2.0

func (c DefaultConverter) AsInt(input any) (int, error)

func (DefaultConverter) AsInt16 added in v0.2.0

func (c DefaultConverter) AsInt16(input any) (int16, error)

func (DefaultConverter) AsInt16Slice added in v0.2.0

func (c DefaultConverter) AsInt16Slice(input any) ([]int16, error)

func (DefaultConverter) AsInt32 added in v0.2.0

func (c DefaultConverter) AsInt32(input any) (int32, error)

func (DefaultConverter) AsInt32Slice added in v0.2.0

func (c DefaultConverter) AsInt32Slice(input any) ([]int32, error)

func (DefaultConverter) AsInt64 added in v0.2.0

func (c DefaultConverter) AsInt64(input any) (int64, error)

func (DefaultConverter) AsInt64Slice added in v0.2.0

func (c DefaultConverter) AsInt64Slice(input any) ([]int64, error)

func (DefaultConverter) AsInt8 added in v0.2.0

func (c DefaultConverter) AsInt8(input any) (int8, error)

func (DefaultConverter) AsInt8Slice added in v0.2.0

func (c DefaultConverter) AsInt8Slice(input any) ([]int8, error)

func (DefaultConverter) AsIntSlice added in v0.2.0

func (c DefaultConverter) AsIntSlice(input any) ([]int, error)

func (DefaultConverter) AsString added in v0.2.0

func (c DefaultConverter) AsString(input any) (string, error)

func (DefaultConverter) AsStringSlice added in v0.2.0

func (c DefaultConverter) AsStringSlice(input any) ([]string, error)

func (DefaultConverter) AsTime added in v0.2.0

func (c DefaultConverter) AsTime(input any) (time.Time, error)

func (DefaultConverter) AsTimeSlice added in v0.2.0

func (c DefaultConverter) AsTimeSlice(input any) ([]time.Time, error)

func (DefaultConverter) AsTimeSliceWithConfig added in v0.2.0

func (c DefaultConverter) AsTimeSliceWithConfig(config TimeConvertConfig, input any) ([]time.Time, error)

func (DefaultConverter) AsTimeWithConfig added in v0.2.0

func (c DefaultConverter) AsTimeWithConfig(config TimeConvertConfig, input any) (time.Time, error)

func (DefaultConverter) AsUint added in v0.2.0

func (c DefaultConverter) AsUint(input any) (uint, error)

func (DefaultConverter) AsUint16 added in v0.2.0

func (c DefaultConverter) AsUint16(input any) (uint16, error)

func (DefaultConverter) AsUint16Slice added in v0.2.0

func (c DefaultConverter) AsUint16Slice(input any) ([]uint16, error)

func (DefaultConverter) AsUint32 added in v0.2.0

func (c DefaultConverter) AsUint32(input any) (uint32, error)

func (DefaultConverter) AsUint32Slice added in v0.2.0

func (c DefaultConverter) AsUint32Slice(input any) ([]uint32, error)

func (DefaultConverter) AsUint64 added in v0.2.0

func (c DefaultConverter) AsUint64(input any) (uint64, error)

func (DefaultConverter) AsUint64Slice added in v0.2.0

func (c DefaultConverter) AsUint64Slice(input any) ([]uint64, error)

func (DefaultConverter) AsUint8 added in v0.2.0

func (c DefaultConverter) AsUint8(input any) (uint8, error)

func (DefaultConverter) AsUint8Slice added in v0.2.0

func (c DefaultConverter) AsUint8Slice(input any) ([]uint8, error)

func (DefaultConverter) AsUintSlice added in v0.2.0

func (c DefaultConverter) AsUintSlice(input any) ([]uint, error)

func (DefaultConverter) ByType added in v0.2.0

func (c DefaultConverter) ByType(input any, asType reflect.Type) (any, error)

ByType attempts to convert the `input` to the type defined by `asType`. It returns error if the convert fails. It first attempts to convert using a quick flow (performance wise) when the target type is a basic type, without using reflect. Then it tries to handle basic type aliases. And then it falls back to reflect usage depending on the target type. If no error is returned then it is safe to use type assertion in the returned value, to the type given in `asType`. e.g.

i, err := c.ByType("123", reflect.TypeOf(int64(0)))
i.(int64) // safe

type DefaultTraverser

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

func NewDefaultTraverser

func NewDefaultTraverser(keyConverter KeyConverter) DefaultTraverser

func (DefaultTraverser) Retrieve

func (d DefaultTraverser) Retrieve(data any, path []Key) (any, error)

type DotNotation

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

func (DotNotation) Format

func (d DotNotation) Format(path ...Key) string

func (DotNotation) Parse

func (d DotNotation) Parse(selector string) ([]Key, error)

type DurationConvertConfig added in v0.2.0

type DurationConvertConfig struct {
	DurationConvertNumberFormat DurationConvertNumberFormat
}

type DurationConvertNumberFormat added in v0.2.0

type DurationConvertNumberFormat int
const (
	DurationNumberNanoseconds DurationConvertNumberFormat = iota // default value
	DurationNumberMilliseconds
	DurationNumberMicroseconds
	DurationNumberSeconds
	DurationNumberMinutes
	DurationNumberHours
)

type ErrorGatherer

type ErrorGatherer interface {
	GatherSelector(selector string, err error)
}

type ErrorsSink

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

func (*ErrorsSink) Gather

func (e *ErrorsSink) Gather(err error)

func (*ErrorsSink) GatherSelector

func (e *ErrorsSink) GatherSelector(selector string, err error)

func (*ErrorsSink) Outcome

func (e *ErrorsSink) Outcome() error

type Integer added in v0.0.2

type Integer interface {
	SignedInteger | UnsignedInteger
}

type Key

type Key struct {
	Name  string
	Index int
	Type  KeyType
}

func Field

func Field(name string) Key

func Index

func Index(idx int) Key

func (Key) Any added in v0.0.2

func (s Key) Any() any

func (Key) IsField

func (s Key) IsField() bool

func (Key) IsIndex

func (s Key) IsIndex() bool

type KeyConverter added in v0.2.0

type KeyConverter interface {
	ByType(input any, asType reflect.Type) (any, error)
	AsInt(item any) (int, error)
}

type KeyType

type KeyType int
const (
	KeyTypeUnknown KeyType = iota
	KeyTypeField
	KeyTypeIndex
)

func (KeyType) String

func (s KeyType) String() string

type Notation

type Notation interface {
	Parse(selector string) ([]Key, error)
	Format(path ...Key) string
}

type Picker

type Picker struct {
	Converter Converter
	// contains filtered or unexported fields
}

func NewPicker

func NewPicker(data any, t Traverser, c Converter, n Notation) Picker

func Wrap

func Wrap(data any) Picker

func WrapDecoder

func WrapDecoder(decoder interface{ Decode(destination any) error }) (Picker, error)

func WrapJSON

func WrapJSON(js []byte) (Picker, error)

func WrapJSONRequest added in v0.1.1

func WrapJSONRequest(r *http.Request) (p Picker, rErr error)

WrapJSONRequest reads the JSON request body from an HTTP request and wraps it into a Picker. It ensures proper cleanup of the request body to prevent resource leaks. Important note: After this function is called the body will be drained and closed.

func WrapJSONResponse added in v0.1.1

func WrapJSONResponse(r *http.Response) (p Picker, rErr error)

WrapJSONResponse reads the JSON response body from an HTTP response and wraps it into a Picker. It ensures proper cleanup of the response body to prevent resource leaks. Important note: After this function is called the body will be drained and closed.

func WrapReaderJSON

func WrapReaderJSON(r io.Reader) (Picker, error)

func (Picker) Any

func (p Picker) Any(selector string) (any, error)

func (Picker) Bool

func (p Picker) Bool(selector string) (bool, error)

func (Picker) BoolSlice

func (p Picker) BoolSlice(selector string) ([]bool, error)

func (Picker) Byte

func (p Picker) Byte(selector string) (byte, error)

func (Picker) ByteSlice

func (p Picker) ByteSlice(selector string) ([]byte, error)

func (Picker) Data

func (p Picker) Data() any

func (Picker) Duration

func (p Picker) Duration(selector string) (time.Duration, error)

func (Picker) DurationSlice

func (p Picker) DurationSlice(selector string) ([]time.Duration, error)

func (Picker) DurationSliceWithConfig

func (p Picker) DurationSliceWithConfig(config DurationConvertConfig, selector string) ([]time.Duration, error)

func (Picker) DurationWithConfig

func (p Picker) DurationWithConfig(config DurationConvertConfig, selector string) (time.Duration, error)

func (Picker) Each

func (p Picker) Each(selector string, operation func(index int, p Picker, length int) error) error

func (Picker) Float32

func (p Picker) Float32(selector string) (float32, error)

func (Picker) Float32Slice

func (p Picker) Float32Slice(selector string) ([]float32, error)

func (Picker) Float64

func (p Picker) Float64(selector string) (float64, error)

func (Picker) Float64Slice

func (p Picker) Float64Slice(selector string) ([]float64, error)

func (Picker) Int

func (p Picker) Int(selector string) (int, error)

func (Picker) Int16

func (p Picker) Int16(selector string) (int16, error)

func (Picker) Int16Slice

func (p Picker) Int16Slice(selector string) ([]int16, error)

func (Picker) Int32

func (p Picker) Int32(selector string) (int32, error)

func (Picker) Int32Slice

func (p Picker) Int32Slice(selector string) ([]int32, error)

func (Picker) Int64

func (p Picker) Int64(selector string) (int64, error)

func (Picker) Int64Slice

func (p Picker) Int64Slice(selector string) ([]int64, error)

func (Picker) Int8

func (p Picker) Int8(selector string) (int8, error)

func (Picker) Int8Slice

func (p Picker) Int8Slice(selector string) ([]int8, error)

func (Picker) IntSlice

func (p Picker) IntSlice(selector string) ([]int, error)

func (Picker) Len

func (p Picker) Len(selector string) (int, error)

func (Picker) Path

func (p Picker) Path(path []Key) (any, error)

func (Picker) Relaxed added in v0.2.0

func (p Picker) Relaxed(onErr ...ErrorGatherer) RelaxedAPI

func (Picker) String

func (p Picker) String(selector string) (string, error)

func (Picker) StringSlice

func (p Picker) StringSlice(selector string) ([]string, error)

func (Picker) Time

func (p Picker) Time(selector string) (time.Time, error)

func (Picker) TimeSlice

func (p Picker) TimeSlice(selector string) ([]time.Time, error)

func (Picker) TimeSliceWithConfig

func (p Picker) TimeSliceWithConfig(config TimeConvertConfig, selector string) ([]time.Time, error)

func (Picker) TimeWithConfig

func (p Picker) TimeWithConfig(config TimeConvertConfig, selector string) (time.Time, error)

func (Picker) Uint

func (p Picker) Uint(selector string) (uint, error)

func (Picker) Uint16

func (p Picker) Uint16(selector string) (uint16, error)

func (Picker) Uint16Slice

func (p Picker) Uint16Slice(selector string) ([]uint16, error)

func (Picker) Uint32

func (p Picker) Uint32(selector string) (uint32, error)

func (Picker) Uint32Slice

func (p Picker) Uint32Slice(selector string) ([]uint32, error)

func (Picker) Uint64

func (p Picker) Uint64(selector string) (uint64, error)

func (Picker) Uint64Slice

func (p Picker) Uint64Slice(selector string) ([]uint64, error)

func (Picker) Uint8

func (p Picker) Uint8(selector string) (uint8, error)

func (Picker) Uint8Slice

func (p Picker) Uint8Slice(selector string) ([]uint8, error)

func (Picker) UintSlice

func (p Picker) UintSlice(selector string) ([]uint, error)

func (Picker) Wrap

func (p Picker) Wrap(data any) Picker

Wrap returns a new Picker using the same traverser, converter and notation.

type PickerError

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

func (*PickerError) Error

func (e *PickerError) Error() string

func (*PickerError) Selector

func (e *PickerError) Selector() string

func (*PickerError) Unwrap

func (e *PickerError) Unwrap() error

type RelaxedAPI added in v0.2.0

type RelaxedAPI struct {
	Picker
	// contains filtered or unexported fields
}

func (RelaxedAPI) Bool added in v0.2.0

func (a RelaxedAPI) Bool(selector string) bool

func (RelaxedAPI) BoolSlice added in v0.2.0

func (a RelaxedAPI) BoolSlice(selector string) []bool

func (RelaxedAPI) Byte added in v0.2.0

func (a RelaxedAPI) Byte(selector string) byte

func (RelaxedAPI) ByteSlice added in v0.2.0

func (a RelaxedAPI) ByteSlice(selector string) []byte

func (RelaxedAPI) Duration added in v0.2.0

func (a RelaxedAPI) Duration(selector string) time.Duration

func (RelaxedAPI) DurationSlice added in v0.2.0

func (a RelaxedAPI) DurationSlice(selector string) []time.Duration

func (RelaxedAPI) DurationSliceWithConfig added in v0.2.0

func (a RelaxedAPI) DurationSliceWithConfig(config DurationConvertConfig, selector string) []time.Duration

func (RelaxedAPI) DurationWithConfig added in v0.2.0

func (a RelaxedAPI) DurationWithConfig(config DurationConvertConfig, selector string) time.Duration

func (RelaxedAPI) Each added in v0.2.0

func (a RelaxedAPI) Each(selector string, operation func(index int, item RelaxedAPI, length int) error)

func (RelaxedAPI) Float32 added in v0.2.0

func (a RelaxedAPI) Float32(selector string) float32

func (RelaxedAPI) Float32Slice added in v0.2.0

func (a RelaxedAPI) Float32Slice(selector string) []float32

func (RelaxedAPI) Float64 added in v0.2.0

func (a RelaxedAPI) Float64(selector string) float64

func (RelaxedAPI) Float64Slice added in v0.2.0

func (a RelaxedAPI) Float64Slice(selector string) []float64

func (RelaxedAPI) Int added in v0.2.0

func (a RelaxedAPI) Int(selector string) int

func (RelaxedAPI) Int16 added in v0.2.0

func (a RelaxedAPI) Int16(selector string) int16

func (RelaxedAPI) Int16Slice added in v0.2.0

func (a RelaxedAPI) Int16Slice(selector string) []int16

func (RelaxedAPI) Int32 added in v0.2.0

func (a RelaxedAPI) Int32(selector string) int32

func (RelaxedAPI) Int32Slice added in v0.2.0

func (a RelaxedAPI) Int32Slice(selector string) []int32

func (RelaxedAPI) Int64 added in v0.2.0

func (a RelaxedAPI) Int64(selector string) int64

func (RelaxedAPI) Int64Slice added in v0.2.0

func (a RelaxedAPI) Int64Slice(selector string) []int64

func (RelaxedAPI) Int8 added in v0.2.0

func (a RelaxedAPI) Int8(selector string) int8

func (RelaxedAPI) Int8Slice added in v0.2.0

func (a RelaxedAPI) Int8Slice(selector string) []int8

func (RelaxedAPI) IntSlice added in v0.2.0

func (a RelaxedAPI) IntSlice(selector string) []int

func (RelaxedAPI) String added in v0.2.0

func (a RelaxedAPI) String(selector string) string

func (RelaxedAPI) StringSlice added in v0.2.0

func (a RelaxedAPI) StringSlice(selector string) []string

func (RelaxedAPI) Time added in v0.2.0

func (a RelaxedAPI) Time(selector string) time.Time

func (RelaxedAPI) TimeSlice added in v0.2.0

func (a RelaxedAPI) TimeSlice(selector string) []time.Time

func (RelaxedAPI) TimeSliceWithConfig added in v0.2.0

func (a RelaxedAPI) TimeSliceWithConfig(config TimeConvertConfig, selector string) []time.Time

func (RelaxedAPI) TimeWithConfig added in v0.2.0

func (a RelaxedAPI) TimeWithConfig(config TimeConvertConfig, selector string) time.Time

func (RelaxedAPI) Uint added in v0.2.0

func (a RelaxedAPI) Uint(selector string) uint

func (RelaxedAPI) Uint16 added in v0.2.0

func (a RelaxedAPI) Uint16(selector string) uint16

func (RelaxedAPI) Uint16Slice added in v0.2.0

func (a RelaxedAPI) Uint16Slice(selector string) []uint16

func (RelaxedAPI) Uint32 added in v0.2.0

func (a RelaxedAPI) Uint32(selector string) uint32

func (RelaxedAPI) Uint32Slice added in v0.2.0

func (a RelaxedAPI) Uint32Slice(selector string) []uint32

func (RelaxedAPI) Uint64 added in v0.2.0

func (a RelaxedAPI) Uint64(selector string) uint64

func (RelaxedAPI) Uint64Slice added in v0.2.0

func (a RelaxedAPI) Uint64Slice(selector string) []uint64

func (RelaxedAPI) Uint8 added in v0.2.0

func (a RelaxedAPI) Uint8(selector string) uint8

func (RelaxedAPI) Uint8Slice added in v0.2.0

func (a RelaxedAPI) Uint8Slice(selector string) []uint8

func (RelaxedAPI) UintSlice added in v0.2.0

func (a RelaxedAPI) UintSlice(selector string) []uint

func (RelaxedAPI) Wrap added in v0.2.0

func (a RelaxedAPI) Wrap(data any) RelaxedAPI

type SignedInteger added in v0.0.2

type SignedInteger interface {
	int | int8 | int16 | int32 | int64
}

type TimeConvertByteSliceFormat added in v0.2.0

type TimeConvertByteSliceFormat int
const (
	TimeConvertByteSliceFormatString TimeConvertByteSliceFormat = iota
	TimeConvertByteSliceFormatBinary
)

type TimeConvertConfig added in v0.2.0

type TimeConvertConfig struct {
	ParseInLocation     *time.Location
	StringFormat        string
	PraseStringAsNumber bool
	NumberFormat        TimeConvertNumberFormat
	ByteSliceFormat     TimeConvertByteSliceFormat
}

type TimeConvertNumberFormat added in v0.2.0

type TimeConvertNumberFormat int
const (
	TimeConvertNumberFormatUnix TimeConvertNumberFormat = iota
	TimeConvertNumberFormatUnixMilli
	TimeConvertNumberFormatUnixMicro
)

type TraverseError

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

func NewTraverseError

func NewTraverseError(msg string, path []Key, fieldIndex int, inner error) *TraverseError

func (*TraverseError) Error

func (t *TraverseError) Error() string

func (*TraverseError) Path

func (t *TraverseError) Path() []Key

func (*TraverseError) Unwrap

func (t *TraverseError) Unwrap() error

type Traverser

type Traverser interface {
	Retrieve(data any, path []Key) (any, error)
}

type UnsignedInteger added in v0.0.2

type UnsignedInteger interface {
	uint | uint8 | uint16 | uint32 | uint64 | uintptr
}

Directories

Path Synopsis
internal
tst

Jump to

Keyboard shortcuts

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