ext

package
v0.0.0-...-389fc93 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package ext 反射扩展

Index

Constants

View Source
const (
	EARTH_RADIUS = 6371393 // 地球半径,单位:米
)

Variables

View Source
var Time timeExt

Functions

func All

func All[T interface{}](slice []T, where func(t T) bool) bool

All 所有数据都满足才返回true

func Any

func Any[T interface{}](slice []T, where func(t T) bool) bool

Any 只要一个满足就返回true

func CheckChanged

func CheckChanged[T interface{}](source []T, target []T, where func(t1 T, t2 T) bool) ([]T, []T, []T)

CheckChanged 比较两个集合,返回 新增、修改、删除 的数据

func ChooseTrueValue

func ChooseTrueValue[T interface{}](condition bool, trueValue, falseValue T) T

ChooseTrueValue 模拟三元表达式,获取值

func Contains

func Contains[T interface{}](slice []T, comparable func(t T) bool) bool

Contains 判断数组是否包含某个项

func ContainsByValue

func ContainsByValue[T comparable](slice []T, e T) bool

ContainsByValue 判断数组是否包含某个项

func Distinct

func Distinct[T comparable](slice []T) []T

Distinct 去重

func FindList

func FindList[T interface{}](slice []T, comparable func(t T) bool) []T

FindList 从数组中返回所有符合条件的项

func FindOne

func FindOne[T interface{}](slice []T, comparable func(t T) bool) T

FindOne 从数组中返回第一个符合条件的项

func FirstOrDefault

func FirstOrDefault[T interface{}](slice []T) T

func Float32ValuePoint

func Float32ValuePoint(value float32) *float32

func Float64ValuePoint

func Float64ValuePoint(value float64) *float64

func GetAuthorizationToken

func GetAuthorizationToken(ctx context.Context) string

func GetDistance

func GetDistance(lon1, lat1, lon2, lat2 float64) float64

GetDistance 计算两个经纬度距离,单位米

func GetMultiDistance

func GetMultiDistance(lon1 float64, lat1 float64, points []*Point) map[int]float64

GetMultiDistance 计算多个经纬度 与 给定坐标的距离,单位米

func GetPath

func GetPath[T interface{}]() string

GetPath 获取类型名称

func GetPathByValue

func GetPathByValue(table interface{}) string

GetPathByValue 获取类型名称

func GetValueByFieldName

func GetValueByFieldName(o interface{}, name string) any

GetValueByFieldName 获取指定字段的值

func GetValueFromContext

func GetValueFromContext(ctx context.Context, key string) string

func GroupBy

func GroupBy[T interface{}, TResult comparable](slice []T, selector func(t T) TResult) map[TResult][]T

GroupBy 分组

func Int32Value

func Int32Value(str *wrapperspb.Int32Value) int32

Int32Value 可空类型 转 string

func Int32ValuePoint

func Int32ValuePoint(value int32) *int32

func Int64ValuePoint

func Int64ValuePoint(value int64) *int64

func IntValuePoint

func IntValuePoint(value int) *int

func Intersect

func Intersect[T comparable](a []T, b []T) []T

Intersect 集合取交集

func IsInherit

func IsInherit[TSource any, Target any]() bool

IsInherit 判断 TSource 是否继承 Target

func IsNotNullOrEmpty

func IsNotNullOrEmpty(str *wrapperspb.StringValue) bool

IsNotNullOrEmpty 判断字符串非空

func IsNullOrEmpty

func IsNullOrEmpty(str *wrapperspb.StringValue) bool

IsNullOrEmpty 判断字符串是空

func IsNullOrEmptyString

func IsNullOrEmptyString(str string) bool

IsNullOrEmptyString 判断字符串是空

func IsPointer

func IsPointer(param interface{}) bool

IsPointer 判断是否是指针

func IsPointerReturnValue

func IsPointerReturnValue(param interface{}) (interface{}, bool)

IsPointerReturnValue 判断是否是指针,并返回真实值

func IsType

func IsType[TSource any, Target any]() (*TSource, *Target, bool)

IsType 判断 TSource 是否等于或者实现 Target

func IsTypeByValue

func IsTypeByValue[T any](value any) (*T, bool)

IsTypeByValue 判断 value 是否等于或者实现 T

func LocalPager

func LocalPager[T interface{}](source []T, page int32, pageSize int32) []T

LocalPager 本地分页

func MaxOne

func MaxOne[T interface{}, TResult interface {
	int | int32 | int64 | float32 | float64
}](slice []T, comparable func(t T) TResult) T

MaxOne 从数组中返回最大值的项

func MaxValue

func MaxValue[T interface{}, TResult interface {
	int | int32 | int64 | float32 | float64
}](slice []T, comparable func(t T) TResult) TResult

MaxValue 从数组中返回最大值

func MinOne

func MinOne[T interface{}, TResult interface {
	int | int32 | int64 | float32 | float64
}](slice []T, comparable func(t T) TResult) T

MinOne 从数组中返回最小值的项

func MinValue

func MinValue[T interface{}, TResult interface {
	int | int32 | int64 | float32 | float64
}](slice []T, comparable func(t T) TResult) TResult

MinValue 从数组中返回最小值

func NumberValuePoint

func NumberValuePoint[T interface {
	int | int32 | int64 | float32 | float64
}](value T) *T

func OrderByNumber

func OrderByNumber[T interface{}, TResult interface {
	int | int32 | int64 | float32 | float64
}](slice []T, asc bool, order func(t T) TResult) []T

func OrderByString

func OrderByString[T interface{}](slice []T, asc bool, order func(t T) string) []T

func Remove

func Remove[T interface{}](source []*T, where func(item *T) bool) []*T

Remove 删除集合中指定元素,返回删除后的数据

func Select

func Select[T interface{}, TResult interface{}](slice []T, selectFunc func(t T) TResult) []TResult

Select 选择单项,返回集合

func SelectMany

func SelectMany[T interface{}, TResult interface{}](slice []T, selectFunc func(t T) []TResult) []TResult

SelectMany 选择集合,返回合并后的集合

func SelectString

func SelectString[T interface{}](slice []T, selectFunc func(t T) string) []string

SelectString 选择字符串,返回集合

func StringValue

func StringValue(str *wrapperspb.StringValue) string

StringValue 可空类型 转 string

func StringValuePoint

func StringValuePoint(value string) *string

func StringWrapper

func StringWrapper(str string) *wrapperspb.StringValue

StringWrapper 字符串包装为可空类型

func Sum

func Sum[T interface{}, TTarget interface {
	int | int32 | int64 | float32 | float64
}](slice []T, selectFunc func(t T) TTarget) TTarget

func ValidatePassword

func ValidatePassword(password string, min int, max int) bool

ValidatePassword 验证密码强度 同时包含大写字母、小写字母、数字、特殊字符,6-16位

Types

type Point

type Point struct {
	Lng  float64 //经度
	Lat  float64 //纬度
	Sort int     //序号
}

Point 经纬度

Jump to

Keyboard shortcuts

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