utils

package
v0.2.0-beta Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetElementType

func GetElementType(rt reflect.Type) reflect.Type

GetElementType 获取实际元素的反射类型

func Has

func Has[T comparable](s []T, x T) bool

Has 查找序列s内是否存在元素x

@param	s	[]T	查找序列
@param	x	T	特定元素
@return	bool true if s contains x, false otherwise

func IsAnonymousStruct

func IsAnonymousStruct(fieldType reflect.Type) bool

IsAnonymousStruct 是否是匿名(未声明)的结构体

func Pluralize

func Pluralize(word string) string

Pluralize 获得一个单词的复数形式,按照语法规则进行变换

func QueryFieldTag

func QueryFieldTag(tag reflect.StructTag, label string, undefined string) string

QueryFieldTag 查找struct字段的Tag

@param	tag			reflect.StructTag	字段的Tag
@param	label		string				要查找的标签
@param	undefined	string				当查找的标签不存在时返回的默认值
@return	string 查找到的标签值, 不存在则返回提供的默认值

func QueryJsonName

func QueryJsonName(tag reflect.StructTag, undefined string) string

QueryJsonName 查询字段定义的json名称

func ReflectFuncName

func ReflectFuncName(handler any) string

ReflectFuncName 反射获得函数名或方法名

func ReflectObjectType

func ReflectObjectType(obj any) reflect.Type

ReflectObjectType 获取任意对象的类型,若为指针,则反射具体的类型

func StringsToFloats

func StringsToFloats(strs []string) []float64

StringsToFloats 将字符串数组转换成float64数组, 简单实现

@param	strs		[]string	输入字符串数组
@return	[]float64 	输出float64数组

func StringsToInts

func StringsToInts(strs []string) []int

StringsToInts 将字符串数组转换成int数组, 简单实现

@param	strs	[]string	输入字符串数组
@return	[]int 	输出int数组

func Ternary

func Ternary[T any](cond bool, ifTrue, ifFalse T) T

Ternary 三元运算符

Types

This section is empty.

Jump to

Keyboard shortcuts

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