reflect_utils

package module
v0.0.0-...-965ef2e Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2022 License: MIT Imports: 4 Imported by: 4

README

Go Reflect Util

提供了Go中常见的一些反射操作,提供一些helpers方法。

go get -u github.com/golang-infrastructure/go-reflect-utils

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSliceHeader

func GetSliceHeader[T any](slice []T) *reflect.SliceHeader

GetSliceHeader 通过反射获取切片的元数据信息

func GetUintPtr

func GetUintPtr(value any) uintptr

GetUintPtr 获取uintptr,不必担心panic的问题

func GetUintPtrE

func GetUintPtrE(value any) (uintptr, error)

GetUintPtrE 获取uintptr,不必担心panic的问题

func IsArrayType

func IsArrayType(v any) bool

IsArrayType 判断值是否是数组类型

func IsArrayValue

func IsArrayValue(v any) bool

IsArrayValue 判断存储的值是否是数组

func IsClosed

func IsClosed[T any](channel chan T) bool

IsClosed 判断channel是否已经被关闭

func IsNil

func IsNil(x any) bool

IsNil 判断参数是否为nil,当只有type但是value为nil的时候会认为是nil

func IsNotNil

func IsNotNil(v any) bool

IsNotNil 判断参数是否不为nil

func IsNotZero

func IsNotZero(v any) bool

IsNotZero 是否是非零,只是IsZero的简单取反

func IsSliceOrArrayType

func IsSliceOrArrayType(v any) bool

IsSliceOrArrayType 判断是是否是切片或者数组类型

func IsSliceOrArrayValue

func IsSliceOrArrayValue(v any) bool

IsSliceOrArrayValue 判断存储的值是否是切片或数组

func IsSliceType

func IsSliceType(v any) bool

IsSliceType 判断是否是切片类型

func IsSliceValue

func IsSliceValue(v any) bool

IsSliceValue 判断存储的值是否是切片

func IsZero

func IsZero(value any) bool

IsZero 是否是零值,如果是nil的也认为是零值 零值包括: 空指针、大小为0的Map、Chan、Slice、Array

func SafeClose

func SafeClose[T any](channel chan T) bool

SafeClose 安全的关闭channel,如果已经被关闭的话会recover住panic 不推荐使用此方法,一个好的结构清晰的代码不应该发生channel被重复关闭的情况,它只会在发送侧关闭一次才对

Types

type Comparator

type Comparator func(a any, b any) int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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