structutil

package
v1.11.4 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2022 License: MIT Imports: 8 Imported by: 3

Documentation

Overview

Utilities for working with and manipulating structs.

Index

Constants

This section is empty.

Variables

View Source
var StopIterating = errors.New(`stop iterating`)
View Source
var StructTag string = `structutil`

Functions

func CopyFunc

func CopyFunc(dest interface{}, source interface{}, fn StructValueFunc) error

func CopyNonZero

func CopyNonZero(dest interface{}, source interface{}) error

Copy all values from the source into the destination, provided the source value for the corresponding field is not that type's zero value.

func FieldsFunc added in v1.7.52

func FieldsFunc(in interface{}, fn StructFieldFunc) error

Iterates over all exported and embedded fields in the given struct, calling fn for each field.

Types

type Field added in v1.8.92

type Field struct {
	*reflect.StructField
	Struct *Struct
}

func (*Field) GetTag added in v1.9.9

func (self *Field) GetTag(label string, fallback ...interface{}) (string, []string, bool)

Retrieve the field name and attributes associated with the given field tag.

func (*Field) Kind added in v1.8.92

func (self *Field) Kind() reflect.Kind

func (*Field) MergeValue added in v1.8.92

func (self *Field) MergeValue(in interface{}) error

func (*Field) Set added in v1.8.92

func (self *Field) Set(value interface{}) error

func (*Field) V added in v1.8.92

func (self *Field) V() typeutil.Variant

func (*Field) Value added in v1.8.92

func (self *Field) Value() reflect.Value

type Struct added in v1.8.92

type Struct struct {
	Source interface{}
	// contains filtered or unexported fields
}

A Struct, or "S-object", can be used to rapidly and safely inspect, iterate over, and modify values of a struct.

func S added in v1.8.92

func S(src interface{}) *Struct

func (*Struct) Field added in v1.8.92

func (self *Struct) Field(name string) (*Field, bool)

func (*Struct) Fields added in v1.8.92

func (self *Struct) Fields() []*Field

func (*Struct) Merge added in v1.8.92

func (self *Struct) Merge(other interface{}) error

type StructFieldFunc added in v1.7.52

type StructFieldFunc func(field *reflect.StructField, value reflect.Value) error

type StructValueFunc

type StructValueFunc func(field string, sourceValue interface{}, destValue interface{}) (interface{}, bool)

Receives a struct field name, the value of that field in the source struct, and the value for that field in the destination struct. Returns the value that should be placed in the destination struct fields. If the returned bool is false, no changes will be made.

Jump to

Keyboard shortcuts

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