util

package
v2.0.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package util implements other tool more, like type cover, type value check.

Usually based on the reflection implementation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapToStructViaJson

func MapToStructViaJson(mapValue any, structPtr any) error

MapToStructViaJson use the map value to set structPtr

func NullDefault

func NullDefault(value, def any) any

NullDefault null value handler to default.

func StructToMap

func StructToMap(value any, ignoreKeys ...string) map[string]any

StructToMap convert Struct field to by Map, support the Ptr

func StructToMapLStyle

func StructToMapLStyle(value any, ignoreKeys ...string) map[string]any

StructToMapLStyle convert Struct field to by Map and key is Lower style, key support `JSON.TAG`. Notice: reflect field num not contain inherit struct.

func StructToMapViaJson

func StructToMapViaJson(value any, ignoreKeys ...string) map[string]any

StructToMapViaJson convert map via json Marshal/Unmarshal StructToMapViaJson is slower than StructToMapLStyle by Benchmark

func ToMapLStyleIgnoreEmpty

func ToMapLStyleIgnoreEmpty(value any, ignoreKeys ...string) map[string]any

ToMapLStyleIgnoreEmpty convert Struct field to by Map and key is Lower style and ignore empty. StructToMapViaJson is slower than StructToMapLStyle by Benchmark

func TryAssignValue

func TryAssignValue(src reflect.Value, tgt reflect.Value) bool

TryAssignValue try assign value to another value.

func ValueNull

func ValueNull(value any) bool

ValueNull to find if is null

Types

type Object

type Object struct {
}

func (Object) Assign

func (obj Object) Assign(target any, source any) any

Assign Base of `reflect` to come true like javascript `Object.Assign`, target should be pointer best. It can be Multiple, only for `reflect.Map`. And support nested struct. @todo 将使用 reflect 与 未使用reflect从包去区分开

func (Object) AssignCovert

func (obj Object) AssignCovert(target any, source any) any

AssignCovert Simple type automatic coverage, supporting cross type. So do not try to cover complex type. number covert any -> string string -> number

func (Object) AssignMap

func (obj Object) AssignMap(targetMap any, srcMapOrStruct any)

AssignMap Assign Map/Struct to map

func (Object) Keys

func (obj Object) Keys(value any) []string

Keys get keys from map or struct.

Notice: map keys maybe disorder.

Directories

Path Synopsis
Package netutil net util, Web related assistant tools
Package netutil net util, Web related assistant tools
Package fs support facilitate for handler file and direction.
Package fs support facilitate for handler file and direction.
Package tm assistant methods related to time reporting
Package tm assistant methods related to time reporting
Package test unit.
Package test unit.
Package xsql extends for the sql package.
Package xsql extends for the sql package.

Jump to

Keyboard shortcuts

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