util

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const (
	// NumberStr 9+26+26+3
	NumberStr = "0123456789abcdefghijklmnopkrstuvwxyzABCDEFGHIJKLMNOPKRSTUVWXYZ+-="
	// N2 进制类型
	N2  = 2
	N8  = 8
	N16 = 16
	N32 = 32
	N36 = 36
	N62 = 62
)

@Date: 2018/12/12 0012 13:45 @Author: Joshua Conero @Name: 10 进制处理

Variables

This section is empty.

Functions

func DecT36 added in v0.4.1

func DecT36(num int) string

DecT36 Data conversion

func DecT62 added in v0.4.1

func DecT62(num int) string

DecT62 Data conversion

func InQue deprecated

func InQue(val any, que []any) int

InQue exist value exist in array, if not exists will return -1

Deprecated: As of Go 1.16, this function simply calls rock.ListIndex.

func InQueAny added in v1.1.0

func InQueAny(que any, keys ...any) int

InQueAny Check keys if exist in Array Or Slice.

func MapToStructViaJson added in v1.4.0

func MapToStructViaJson(mapValue any, structPtr any) error

MapToStructViaJson use the map value to set structPtr

func NullDefault added in v1.1.0

func NullDefault(value, def any) any

NullDefault null value handler to default.

func Round added in v0.2.0

func Round(num float64, b int) float64

Round String method processing float equal length data specified digits

func SpendTimeDiff added in v1.1.0

func SpendTimeDiff() func() time.Duration

SpendTimeDiff Get the program spend time for any format.

func StructToMap added in v1.1.0

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

StructToMap convert Struct field to by Map, support the Ptr

func StructToMapLStyle added in v1.1.0

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 added in v1.1.0

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 added in v1.1.0

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 added in v1.4.0

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

TryAssignValue try assign value to another value.

func ValueNull added in v1.1.0

func ValueNull(value any) bool

ValueNull to find if is null

Types

type Decimal added in v0.4.1

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

func NewDec added in v0.4.1

func NewDec(dec int) *Decimal

NewDec decimal system

func (*Decimal) T16 added in v0.4.1

func (d *Decimal) T16() string

T16 16 Base system

func (*Decimal) T2 added in v0.4.1

func (d *Decimal) T2() string

T2 2 Base system

func (*Decimal) T32 added in v0.4.1

func (d *Decimal) T32() string

T32 32 Base system

func (*Decimal) T36 added in v0.4.1

func (d *Decimal) T36() string

T36 36 Base system

func (*Decimal) T62 added in v0.4.1

func (d *Decimal) T62() string

func (*Decimal) T8 added in v0.4.1

func (d *Decimal) T8() string

T8 8 Base system

func (*Decimal) ToN added in v0.4.1

func (d *Decimal) ToN(base int) string

ToN convert to n-ary

type Object added in v1.1.0

type Object struct {
}

func (Object) Assign added in v1.1.0

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 added in v1.3.0

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 added in v1.1.0

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

AssignMap Assign Map/Struct to map

func (Object) Keys added in v1.2.0

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

Keys get keys from map or struct.

Notice: map keys maybe disorder.

Directories

Path Synopsis
Package rock As the cornerstone of implementing generic methods, implementing generic related operations with minimal dependencies.
Package rock As the cornerstone of implementing generic methods, implementing generic related operations with minimal dependencies.

Jump to

Keyboard shortcuts

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