cpy

package
v4.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All(toObj any, fromObj any) error

All Copy everything from one to another

func ErrCopyFromObjectInvalid

func ErrCopyFromObjectInvalid() error

ErrCopyFromObjectInvalid Error: Copy from object is invalid

func ErrCopyToObjectUnaddressable

func ErrCopyToObjectUnaddressable() error

ErrCopyToObjectUnaddressable Error: Copy to object is unaddressable

func ErrTypeMapNotEqual

func ErrTypeMapNotEqual() error

ErrTypeMapNotEqual Error: Type of map is not equal

func Filter

func Filter(toObj any, fromObj any, filter FilterFn) error

Filter Copy everything data which filtration, used for array, slice and map

func Omit

func Omit(toObj any, fromObj any, fields ...string) error

Omit Copy everything from one to another, but skip listed fields. Use for struct only

func Select

func Select(toObj any, fromObj any, fields ...string) error

Select Copy only the selected fields. Use for struct only

Types

type Cpy

type Cpy struct{}

Cpy Объект сущности пакета.

func Gist

func Gist() *Cpy

Gist Интерфейс к служебным методам.

func (*Cpy) Check

func (cpy *Cpy) Check(to reflect.Value, from reflect.Value) (isSlice bool, size int, err error)

Check if input objects is correct

func (*Cpy) Copy

func (cpy *Cpy) Copy(toObj any, fromObj any, selected []string, omit []string, filter FilterFn) (err error)

Copy everything

func (*Cpy) CopyFromField

func (cpy *Cpy) CopyFromField(
	_ reflect.Type,
	fromT reflect.Type,
	dst reflect.Value,
	src reflect.Value,
	selected []string,
	omit []string,
	filter FilterFn,
) (err error)

CopyFromField Copy from field to field or method

func (*Cpy) CopyFromMethod

func (cpy *Cpy) CopyFromMethod(
	toT reflect.Type,
	_ reflect.Type,
	dst reflect.Value,
	src reflect.Value,
	selected []string,
	omit []string,
	filter FilterFn,
) (err error)

CopyFromMethod Copy from method to field

func (*Cpy) CopyToIsZero

func (cpy *Cpy) CopyToIsZero(toRv reflect.Value, fromRv reflect.Value) (err error)

CopyToIsZero Копирование значений только если значение в объекте назначения пустое.

func (*Cpy) ErrCopyFromObjectInvalid

func (cpy *Cpy) ErrCopyFromObjectInvalid() error

ErrCopyFromObjectInvalid Error: Copy from object is invalid

func (*Cpy) ErrCopyToObjectUnaddressable

func (cpy *Cpy) ErrCopyToObjectUnaddressable() error

ErrCopyToObjectUnaddressable Error: Copy to object is unaddressable

func (*Cpy) ErrTypeMapNotEqual

func (cpy *Cpy) ErrTypeMapNotEqual() error

ErrTypeMapNotEqual Error: Type of map is not equal

func (*Cpy) FieldReplaceName

func (cpy *Cpy) FieldReplaceName(field reflect.StructField, name string) (ret string)

FieldReplaceName Get field name from tag

func (*Cpy) Fields

func (cpy *Cpy) Fields(rt reflect.Type) (ret []reflect.StructField)

Fields to StructField

func (*Cpy) Indirect

func (cpy *Cpy) Indirect(rv reflect.Value) reflect.Value

Indirect value get

func (*Cpy) IndirectType

func (cpy *Cpy) IndirectType(reflectType reflect.Type) reflect.Type

IndirectType Indirect type get

func (*Cpy) IsSkip

func (cpy *Cpy) IsSkip(selected []string, omit []string, srcName string, dstName string) (ret bool)

IsSkip Return true for skip field

func (*Cpy) Set

func (cpy *Cpy) Set(to reflect.Value, from reflect.Value) (ok bool, err error)

Set value

func (*Cpy) SetToFieldIsZero

func (cpy *Cpy) SetToFieldIsZero(toRv reflect.Value, toName string, fromV reflect.Value) (err error)

SetToFieldIsZero Копирование одного поля по имени, только если значение в объекте назначения пустое.

func (*Cpy) SetToFieldOrMethod

func (cpy *Cpy) SetToFieldOrMethod(
	dst reflect.Value,
	dstName string,
	from reflect.Value,
	_ string,
	selected []string,
	omit []string,
	filter FilterFn,
) (err error)

SetToFieldOrMethod Set value to field or method

func (*Cpy) SetToIsZero

func (cpy *Cpy) SetToIsZero(to reflect.Value, from reflect.Value) (ok bool, err error)

SetToIsZero Установка значения только если значение получателя является пустым значением.

type FilterFn

type FilterFn func(key any, object any) (skip bool)

FilterFn Тип функции фильтрации. Вернётся "истина", для пропуска данных.

Jump to

Keyboard shortcuts

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