gocast

package module
v2.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 10 Imported by: 34

README

GoCast

GoDoc Build Status Go Report Card Coverage Status

Introduction

GoCast is a powerful Go library that allows you to easily convert between different basic types in a consistent and efficient way. Whether you need to convert strings, numbers, or other basic types, GoCast has got you covered.

Features

  • Universal Type Casting: GoCast provides a set of methods for universal type casting, making it easy to convert data between various types.
  • Struct Field Manipulation: GoCast allows you to set and retrieve values of struct fields dynamically, making it a valuable tool for working with complex data structures.
  • Custom Type Support: You can define custom types and implement your own conversion logic, giving you full control over how data is cast.

Installation

To use GoCast in your Go project, simply import it:

import "github.com/demdxx/gocast/v2"

Usage Example

Here are some examples of how you can use GoCast:

// Example string casting:
gocast.Str("strasstr")           // "strasstr"
gocast.Str(8)                    // "8"
gocast.Str(8.31)                 // "8.31"
gocast.Str([]byte("one time"))   // "one time"
gocast.Str(nil)                  // ""

// Example number casting:
gocast.Number[int](8)            // 8
gocast.Number[int](8.31)         // 8
gocast.Number[int]("8")          // 8
gocast.Number[int](true)         // 1
gocast.Number[int](false)        // 0

var eight any = 8
gocast.Number[int](eight)        // 8
gocast.Cast[int](eight)          // 8
gocast.Number[int](nil)          // 0

// Number converts only into numeric values (simpler and faster then Cast)
gocast.Number[float32]("2.12")   // 2.12

// Cast converts any type to any other type
gocast.Cast[float64]("2.")       // 2.0

val, err := gocast.TryCast[int]("123.2") // 123, <nil>

res := gocast.Map[string, any](struct{ID int64}{ID: 1}) // map[string]any{"ID": 1}
func sumAll(vals ...any) int {
  var result int = 0
  for _, v := range vals {
    result += gocast.Number[int](v)
  }
  return result
}

Struct Field Manipulation

GoCast also allows you to work with struct fields dynamically:

type User struct {
  ID    uint64
  Email string
}

var user User

// Set structure values
err := gocast.SetStructFieldValue(&user, "ID", uint64(19))
err := gocast.SetStructFieldValue(&user, "Email", "iamawesome@mail.com")

id, err := gocast.StructFieldValue(user, "ID")
email, err := gocast.StructFieldValue(user, "Email")
fmt.Printf("User: %d - %s", id, email)
// > User: 19 - iamawesome@mail.com

Custom Type Support

You can define and use custom types with GoCast:

// Define custom type
type Money int64

func (m *Money) CastSet(ctx context.Context, v any) error {
  switch val := v.(type) {
  case Money:
    *m = val
  default:
    *m = Money(gocast.Float64(v) * 1000000)
  }
  return nil
}

// Use custom type in structs
type Car struct {
  ID int64
  Price Money
}

var car Car

// Mapping values into struct
gocast.TryCopyStruct(&car, map[string]any{"ID":1, "Price": "12000.00"})

Benchmarks

Here are some benchmark results for GoCast:

> go test -benchmem -v -race -bench=.

goos: darwin
goarch: amd64
pkg: github.com/demdxx/gocast/v2
BenchmarkApproachTest
BenchmarkApproachTest/bench1
BenchmarkApproachTest/bench1-24           348097         3064 ns/op        0 B/op          0 allocs/op
BenchmarkApproachTest/bench2
BenchmarkApproachTest/bench2-24           394160         3005 ns/op        0 B/op          0 allocs/op
BenchmarkBool
BenchmarkBool-24                        20453542           58.87 ns/op             0 B/op          0 allocs/op
BenchmarkToBoolByReflect
BenchmarkToBoolByReflect-24             17354990           70.62 ns/op             0 B/op          0 allocs/op
BenchmarkToFloat
BenchmarkToFloat-24                     10951923          107.0 ns/op              0 B/op          0 allocs/op
BenchmarkToInt
BenchmarkToInt-24                        9870794          121.1 ns/op              0 B/op          0 allocs/op
BenchmarkToUint
BenchmarkToUint-24                       9729873          121.3 ns/op              0 B/op          0 allocs/op
BenchmarkToStringByReflect
BenchmarkToStringByReflect-24             922710         1601 ns/op        5 B/op          0 allocs/op
BenchmarkToString
BenchmarkToString-24                      836929         1622 ns/op        5 B/op          0 allocs/op
BenchmarkGetSetFieldValue
BenchmarkGetSetFieldValue/set
BenchmarkGetSetFieldValue/set-24         1000000         1021 ns/op       64 B/op          4 allocs/op
BenchmarkGetSetFieldValue/get
BenchmarkGetSetFieldValue/get-24         1869465          643.8 ns/op             48 B/op          3 allocs/op
BenchmarkParseTime
BenchmarkParseTime-24                     374346         3130 ns/op      700 B/op         17 allocs/op
BenchmarkIsEmpty
BenchmarkIsEmpty-24                     37383031           31.23 ns/op             0 B/op          0 allocs/op
PASS
ok      github.com/demdxx/gocast/v2     17.982s

License

GoCast is released under the MIT License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidParams                 = errors.New("invalid params")
	ErrUnsupportedType               = errors.New("unsupported destination type")
	ErrUnsupportedSourceType         = errors.New("unsupported source type")
	ErrUnsettableValue               = errors.New("can't set value")
	ErrUnsupportedNumericType        = errors.New("unsupported numeric type")
	ErrStructFieldNameUndefined      = errors.New("struct field name undefined")
	ErrStructFieldValueCantBeChanged = errors.New("struct field value cant be changed")
)

Error list...

View Source
var (
	ErrWalkSkip = errors.New("skip field walk")
	ErrWalkStop = errors.New("stop field walk")
)

Functions

func AnySlice added in v2.6.0

func AnySlice[R any](src any, tags ...string) []R

AnySlice converts any input slice into destination type slice as return value

func AnySliceContext added in v2.6.0

func AnySliceContext[R any](ctx context.Context, src any, tags ...string) []R

AnySliceContext converts any input slice into destination type slice as return value

func Bool

func Bool(v any) bool

Bool from any other basic types

func Cast

func Cast[R any, T any](v T, tags ...string) R

Cast source type into the target type

func CastContext added in v2.2.3

func CastContext[R any, T any](ctx context.Context, v T, tags ...string) R

CastContext source type into the target type

func CastRecursive

func CastRecursive[R any, T any](v T, tags ...string) R

CastRecursive source type into the target type

func CastRecursiveContext added in v2.2.3

func CastRecursiveContext[R any, T any](ctx context.Context, v T, tags ...string) R

CastRecursiveContext source type into the target type

func Float

func Float(v any) float64

Float from any other basic type, float64 by default

func Float32

func Float32(v any) float32

Float32 from any other basic type

func Float64

func Float64(v any) float64

Float64 from any other basic type

func IfThen added in v2.8.0

func IfThen[T any](cond bool, a, b T) T

IfThen returns a if cond is true, else b

func IfThenExec added in v2.9.0

func IfThenExec[T any](cond bool, a func() T, b func() T) T

IfThenExec returns a() if cond is true, else b()

func Int

func Int(v any) int

Int from any other basic type

func Int16

func Int16(v any) int16

Int16 from any other basic type

func Int32

func Int32(v any) int32

Int32 from any other basic type

func Int64

func Int64(v any) int64

Int64 from any other basic type

func Int8

func Int8(v any) int8

Int8 from any other basic type

func IsEmpty

func IsEmpty[T any](v T) bool

IsEmpty checks value for empty state

func IsEmptyByReflection

func IsEmptyByReflection(v reflect.Value) bool

IsEmptyByReflection value

func IsMap added in v2.6.0

func IsMap(v any) bool

IsMap checks if the input value is a Map/Object type

func IsNumeric10Str added in v2.6.0

func IsNumeric10Str(s string) bool

IsNumeric10Str returns true if input string is a numeric in base 10

func IsNumericOnlyStr added in v2.6.0

func IsNumericOnlyStr(s string) bool

IsNumericOnlyStr returns true if input string is a numeric only

func IsNumericStr added in v2.6.0

func IsNumericStr(s string) bool

IsNumeric returns true if input is a numeric

func IsSlice added in v2.5.0

func IsSlice(v any) bool

IsSlice returns true if v is a slice or array

func IsStr added in v2.6.2

func IsStr(v any) bool

IsStr returns true if value is string

func IsStrContainsOf added in v2.6.0

func IsStrContainsOf(s, subset string) bool

IsStrContainsOf returns true if input string contains only chars from subset

func IsStruct added in v2.6.1

func IsStruct(v any) bool

IsStruct returns true if the value is a struct

func Len added in v2.4.0

func Len[T any](val T) int

Len returns size of slice, array or map

func Map

func Map[K comparable, V any](src any, tags ...string) map[K]V

Map creates map from source or returns nil

func MapContext added in v2.3.0

func MapContext[K comparable, V any](ctx context.Context, src any, tags ...string) map[K]V

MapContext creates map from source or returns nil

func MapRecursive

func MapRecursive[K comparable, V any](src any, tags ...string) map[K]V

MapRecursive creates map from source or returns nil

func MapRecursiveContext added in v2.3.0

func MapRecursiveContext[K comparable, V any](ctx context.Context, src any, tags ...string) map[K]V

MapRecursiveContext creates map from source or returns nil

func Number

func Number[R Numeric](v any) R

Number converts from types which could be numbers or returns 0

func Or added in v2.8.0

func Or[T any](a, b T, v ...T) T

Or returns the first non-empty value

func ParseTime

func ParseTime(tm string) (t time.Time, err error)

ParseTime from string

func PtrAsValue added in v2.8.1

func PtrAsValue[T any](v *T, def T) T

PtrAsValue returns the value of `v` if `v` is not `nil`, else def

func ReflectStr

func ReflectStr(v reflect.Value) string

ReflectStr converts reflection value to string

func ReflectStructAllFieldNames added in v2.7.2

func ReflectStructAllFieldNames(t reflect.Type, tags ...string) map[string][]string

ReflectStructAllFieldNames returns the field names from the structure including names from tags

func ReflectStructAllFieldNamesContext added in v2.7.2

func ReflectStructAllFieldNamesContext(ctx context.Context, t reflect.Type, tags ...string) map[string][]string

ReflectStructAllFieldNamesContext returns the field names from the structure including names from tags

func ReflectStructFieldNames added in v2.7.0

func ReflectStructFieldNames(t reflect.Type, tag string) []string

ReflectStructFieldNames returns the field names from the structure

func ReflectStructFieldTagsUnsorted added in v2.7.0

func ReflectStructFieldTagsUnsorted(t reflect.Type, tag string) ([]string, []string)

ReflectStructFieldTagsUnsorted returns field names and tag targets separately

func ReflectStructFieldValue added in v2.2.1

func ReflectStructFieldValue(st reflect.Value, names ...string) (any, error)

ReflectStructFieldValue returns the value of the struct field

func ReflectStructFields added in v2.7.0

func ReflectStructFields(t reflect.Type) []reflect.StructField

ReflectStructFields returns the field names from the structure

func ReflectToBool

func ReflectToBool(v reflect.Value) bool

ReflectToBool returns boolean from reflection

func ReflectToFloat64

func ReflectToFloat64(v reflect.Value) float64

ReflectToFloat64 returns float64 from reflection

func ReflectToInt64

func ReflectToInt64(v reflect.Value) int64

ReflectToInt64 returns int64 from reflection

func ReflectToString deprecated

func ReflectToString(v reflect.Value) string

ReflectToString converts reflection value to string

Deprecated: Use TryReflectStr instead

func ReflectToType

func ReflectToType(v reflect.Value, t reflect.Type, tags ...string) any

ReflectToType converts reflection valut to reflection type or returns nil

func ReflectToTypeContext added in v2.2.3

func ReflectToTypeContext(ctx context.Context, v reflect.Value, t reflect.Type, tags ...string) any

ReflectToType converts reflection valut to reflection type or returns nil

func ReflectTryToType

func ReflectTryToType(v reflect.Value, t reflect.Type, recursive bool, tags ...string) (any, error)

ReflectTryToType converts reflection value to reflection type or returns error

func ReflectTryToTypeContext added in v2.2.3

func ReflectTryToTypeContext(ctx context.Context, srcVal reflect.Value, t reflect.Type, recursive bool, tags ...string) (any, error)

ReflectTryToTypeContext converts reflection value to reflection type or returns error

func SetStructFieldValue

func SetStructFieldValue(ctx context.Context, st any, name string, value any) (err error)

SetStructFieldValue puts value into the struct field

func Slice

func Slice[R any, S any](src []S, tags ...string) []R

Slice converts one type of array to other or resturns nil if not compatible

func SliceContext added in v2.2.3

func SliceContext[R any, S any](ctx context.Context, src []S, tags ...string) []R

SliceContext converts one type of array to other or resturns nil if not compatible

func Str

func Str(v any) string

Str returns string value from any type

func Struct

func Struct[R any](src any, tags ...string) (R, error)

Struct convert any input type into the target structure

func StructAllFieldNames added in v2.7.2

func StructAllFieldNames(st any, tags ...string) map[string][]string

StructAllFieldNames returns the field names from the structure including names from tags

func StructAllFieldNamesContext added in v2.7.2

func StructAllFieldNamesContext(ctx context.Context, st any, tags ...string) map[string][]string

StructAllFieldNamesContext returns the field names from the structure including names from tags

func StructContext added in v2.2.0

func StructContext[R any](ctx context.Context, src any, tags ...string) (R, error)

StructContext convert any input type into the target structure

func StructFieldNames added in v2.7.0

func StructFieldNames(st any, tag string) []string

StructFieldNames returns the field names from the structure

func StructFieldTags

func StructFieldTags(st any, tag string) map[string]string

StructFieldTags returns Map with key->tag matching

func StructFieldTagsUnsorted

func StructFieldTagsUnsorted(st any, tag string) ([]string, []string)

StructFieldTagsUnsorted returns field names and tag targets separately

func StructFieldValue

func StructFieldValue(st any, names ...string) (any, error)

StructFieldValue returns the value of the struct field

func StructWalk added in v2.8.0

func StructWalk(ctx context.Context, v any, walker structWalkerFunc, options ...WalkOption) error

StructWalk walks the struct recursively

func To

func To(v, to any, tags ...string) any

TryTo cast any input type into the target

func ToBool deprecated

func ToBool(v any) bool

ToBool from any other basic types

Deprecated: Use Bool(v) instead

func ToFloat deprecated

func ToFloat(v any) float64

ToFloat from any other basic types

Deprecated: Use Number[float64](v) instead

func ToFloat32 deprecated

func ToFloat32(v any) float32

ToFloat32 from any other basic types

Deprecated: Use Number[float32](v) instead

func ToFloat64 deprecated

func ToFloat64(v any) float64

ToFloat64 from any other basic types

Deprecated: Use Number[float64](v) instead

func ToFloat64Slice deprecated

func ToFloat64Slice(v any) []float64

ToFloat64Slice converts any input slice into Float64 type slice

Deprecated: Use Slice[float64](v) or AnySlice[float64](v) instead

func ToInt deprecated

func ToInt(v any) int

ToInt from any other basic types

Deprecated: Use Number[int](v) or Int instead

func ToInt16 deprecated

func ToInt16(v any) int16

ToInt16 from any other basic types

Deprecated: Use Number[int16](v) or Int16 instead

func ToInt32 deprecated

func ToInt32(v any) int32

ToInt32 from any other basic types

Deprecated: Use Number[int32](v) or Int32 instead

func ToInt64 deprecated

func ToInt64(v any) int64

ToInt64 from any other basic types

Deprecated: Use Number[int64](v) or Int64 instead

func ToIntSlice deprecated

func ToIntSlice(v any) []int

ToIntSlice converts any input slice into Int type slice

Deprecated: Use Slice[int](v) or AnySlice[int](v) instead

func ToInterfaceSlice deprecated

func ToInterfaceSlice(v any) []any

ToInterfaceSlice converts any input slice into Interface type slice

Deprecated: Use Slice[any](v) or AnySlice[any](v) instead

func ToMap

func ToMap(dst, src any, recursive bool, tags ...string) error

ToMap cast your Source into the Destination type tag defines the tags name in the structure to map the keys

func ToMapContext added in v2.3.0

func ToMapContext(ctx context.Context, dst, src any, recursive bool, tags ...string) error

ToMap cast your Source into the Destination type tag defines the tags name in the structure to map the keys

func ToMapFrom

func ToMapFrom(src any, recursive bool, tags ...string) (map[any]any, error)

ToMapFrom any Map/Object type

func ToSiMap deprecated

func ToSiMap(src any, recursive bool, tags ...string) (map[string]any, error)

ToSiMap converts input Map/Object type into the map[string]any

Deprecated: Use TryMapFrom[string, any](...) instead

func ToSlice deprecated

func ToSlice(dst, src any, tags ...string) error

ToSlice converts any input slice into destination type slice

Deprecated: Use Slice[type](v) or TrySlice[type](v) or AnySlice[type](v) or TryAnySlice[type](v) instead

func ToString deprecated

func ToString(v any) string

ToString from any type

Deprecated: Use Str instead

func ToStringMap deprecated

func ToStringMap(src any, recursive bool, tags ...string) (map[string]string, error)

ToStringMap converts input Map/Object type into the map[string]string

Deprecated: Use TryMapFrom[string, string](...) instead

func ToStringSlice deprecated

func ToStringSlice(v any) []string

ToStringSlice converts any input slice into String type slice

Deprecated: Use Slice[string](v) or AnySlice[string](v) instead

func ToStruct deprecated

func ToStruct(dst, src any, tags ...string) error

ToStruct convert any input type into the target structure

Deprecated: Use TryCopyStruct instead

func ToType

func ToType(v any, t reflect.Type, tags ...string) any

ToType cast any input type into the target reflection

func ToUint deprecated

func ToUint(v any) uint

ToUint from any other basic types

Deprecated: Use Number[uint](v) or Uint instead

func ToUint16 deprecated

func ToUint16(v any) uint16

ToUint32 from any other basic types

Deprecated: Use Number[uint16](v) or Uint16 instead

func ToUint32 deprecated

func ToUint32(v any) uint32

ToUint32 from any other basic types

Deprecated: Use Number[uint32](v) or Uint32 instead

func ToUint64 deprecated

func ToUint64(v any) uint64

ToUint64 from any other basic types

Deprecated: Use Number[uint64](v) or Uint64 instead

func ToUint64ByReflect

func ToUint64ByReflect(v reflect.Value) uint64

ToUint64ByReflect returns uint64 from reflection

func TryAnySlice added in v2.6.0

func TryAnySlice[R any](src any, tags ...string) (res []R, err error)

TryToAnySlice converts any input slice into destination type slice as return value

func TryAnySliceContext added in v2.2.3

func TryAnySliceContext[R any](ctx context.Context, src any, tags ...string) ([]R, error)

TryAnySliceContext converts any input slice into destination type slice as return value

func TryCast

func TryCast[R any, T any](v T, tags ...string) (R, error)

TryCast source type into the target type

func TryCastContext added in v2.2.3

func TryCastContext[R any, T any](ctx context.Context, v T, tags ...string) (R, error)

TryCastContext source type into the target type

func TryCastRecursive

func TryCastRecursive[R any, T any](v T, tags ...string) (R, error)

TryCastRecursive source type into the target type with recursive data converting

func TryCastRecursiveContext added in v2.2.3

func TryCastRecursiveContext[R any, T any](ctx context.Context, v T, tags ...string) (R, error)

TryCastRecursiveContext source type into the target type with recursive data converting

func TryCastValue

func TryCastValue[R any, T any](v T, recursive bool, tags ...string) (R, error)

TryCastValue source type into the target type

func TryCastValueContext added in v2.2.3

func TryCastValueContext[R any, T any](ctx context.Context, v T, recursive bool, tags ...string) (R, error)

TryCastValueContext source type into the target type

func TryCopyStruct

func TryCopyStruct(dst, src any, tags ...string) (err error)

TryCopyStruct convert any input type into the target structure

func TryCopyStructContext added in v2.2.0

func TryCopyStructContext(ctx context.Context, dst, src any, tags ...string) (err error)

TryCopyStructContext convert any input type into the target structure

func TryMap

func TryMap[K comparable, V any](src any, tags ...string) (map[K]V, error)

TryMap creates new map to convert from soruce type

func TryMapContext added in v2.3.0

func TryMapContext[K comparable, V any](ctx context.Context, src any, tags ...string) (map[K]V, error)

TryMapContext creates new map to convert from soruce type

func TryMapCopy

func TryMapCopy[K comparable, V any](dst map[K]V, src any, recursive bool, tags ...string) error

TryMapCopy converts source into destination or return error

func TryMapCopyContext added in v2.3.0

func TryMapCopyContext[K comparable, V any](ctx context.Context, dst map[K]V, src any, recursive bool, tags ...string) error

TryMapCopyContext converts source into destination or return error

func TryMapFrom

func TryMapFrom[K comparable, V any](src any, recursive bool, tags ...string) (map[K]V, error)

TryMapFrom source creates new map to convert

func TryMapFromContext added in v2.3.0

func TryMapFromContext[K comparable, V any](ctx context.Context, src any, recursive bool, tags ...string) (map[K]V, error)

TryMapFrom source creates new map to convert

func TryMapRecursive

func TryMapRecursive[K comparable, V any](src any, tags ...string) (map[K]V, error)

TryMapRecursive creates new map to convert from soruce type with recursive field processing

func TryMapRecursiveContext added in v2.3.0

func TryMapRecursiveContext[K comparable, V any](ctx context.Context, src any, tags ...string) (map[K]V, error)

TryMapRecursiveContext creates new map to convert from soruce type with recursive field processing

func TryNumber

func TryNumber[R Numeric](v any) (R, error)

TryNumber converts from types which could be numbers

func TryReflectStr

func TryReflectStr(v reflect.Value) (string, error)

TryReflectStr converts reflection value to string

func TryReflectToString deprecated

func TryReflectToString(v reflect.Value) (string, error)

TryReflectToString converts reflection value to string

Deprecated: Use TryReflectStr instead

func TrySlice

func TrySlice[R any, S any](src []S, tags ...string) (res []R, err error)

TrySlice converts one type of array to other or resturns error

func TrySliceContext added in v2.2.3

func TrySliceContext[R any, S any](ctx context.Context, src []S, tags ...string) (res []R, err error)

TrySliceContext converts one type of array to other or resturns error

func TryStr

func TryStr(v any) (string, error)

TryStr from any type

func TryTo

func TryTo(v, to any, tags ...string) (any, error)

TryTo cast any input type into the target

func TryToAnySliceContext added in v2.6.0

func TryToAnySliceContext(ctx context.Context, dst, src any, tags ...string) error

TryToAnySliceContext converts any input slice into destination type slice

func TryToContext added in v2.2.3

func TryToContext(ctx context.Context, v, to any, tags ...string) (any, error)

TryToContext cast any input type into the target

func TryToString deprecated

func TryToString(v any) (string, error)

TryToString returns string value from any type

Deprecated: Use TryStr instead

func TryToType

func TryToType(v any, t reflect.Type, tags ...string) (any, error)

TryToType cast any input type into the target reflection

func TryToTypeContext added in v2.2.3

func TryToTypeContext(ctx context.Context, v any, t reflect.Type, tags ...string) (any, error)

TryToTypeContext cast any input type into the target reflection

func Uint

func Uint(v any) uint

Uint from any other basic type

func Uint16

func Uint16(v any) uint16

Uint16 from any other basic type

func Uint32

func Uint32(v any) uint32

Uint32 from any other basic type

func Uint64

func Uint64(v any) uint64

Uint64 from any other basic type

func Uint8

func Uint8(v any) uint8

Uint8 from any other basic type

Types

type CastSetter added in v2.1.1

type CastSetter interface {
	CastSet(ctx context.Context, v any) error
}

CastSetter interface from some type into the specific value

type Numeric

type Numeric interface {
	constraints.Integer | constraints.Float
}

Numeric data type

type StructWalkField added in v2.8.0

type StructWalkField interface {
	Name() string
	Tag(name string) string
	IsEmpty() bool
	RefValue() reflect.Value
	Value() any
	SetValue(ctx context.Context, v any) error
}

StructWalkField is the type of the field visited by StructWalk

type StructWalkObject added in v2.8.0

type StructWalkObject interface {
	Parent() StructWalkObject
	RefValue() reflect.Value
	Struct() any
}

type StructWalkOptions added in v2.8.0

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

StructWalkOptions is the options for StructWalk

func (*StructWalkOptions) PathName added in v2.8.0

func (w *StructWalkOptions) PathName(ctx context.Context, curObj StructWalkObject, field StructWalkField, path []string) string

PathName returns the path name of the current field

type WalkOption added in v2.8.0

type WalkOption func(w *StructWalkOptions)

WalkOption is the option for StructWalk

func WalkWithPathExtractor added in v2.8.0

func WalkWithPathExtractor(fn structWalkerNameFunc) WalkOption

WalkWithPathExtractor sets the path extractor for StructWalk

func WalkWithPathTag added in v2.8.0

func WalkWithPathTag(tagName string) WalkOption

WalkWithPathTag sets the path tag for StructWalk

Jump to

Keyboard shortcuts

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