utils

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: AGPL-3.0 Imports: 46 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AesCbcBase64 added in v0.5.1

func AesCbcBase64(src, productSecret string) (string, error)

func AnyToDecimal

func AnyToDecimal(num string, n int) int64

任意进制转10进制

func AnyToNullString added in v0.3.1

func AnyToNullString(in any) sql.NullString

func CheckPasswordLever

func CheckPasswordLever(ps string) int32

检测密码是否符合规范 需要至少8位 并且需要包含数字和字母

密码强度必须为字⺟⼤⼩写+数字+符号,9位以上

func CheckUserName

func CheckUserName(name string) error

检测用户名是否符合规范 只可以使用字母数字及下划线 最多30个字符

func Convert

func Convert(src any, dst any) any

@in src 赋值的数据源 @in dst 赋值对象的结构体 @out dst类型的结构体

func CopyContext added in v0.4.1

func CopyContext(ctx context.Context) context.Context

func Decimal

func Decimal[valueType constraints.Float](value valueType, n int) valueType

保留n位小数

func DecimalToAny

func DecimalToAny(num, n int64) string

10进制转任意进制

func FillZeroToLen added in v0.5.1

func FillZeroToLen(src string, length int) string

func FirstLower added in v0.5.1

func FirstLower(s string) string

FirstLower 字符串首字母小写

func FirstUpper added in v0.5.1

func FirstUpper(s string) string

FirstUpper 字符串首字母大写

func Fmt

func Fmt(v any) string

Fmt 将结构以更方便看的方式打印出来

func FuncName

func FuncName() string

获取正在运行的函数名

func GetIP

func GetIP(r *http.Request) (string, error)

@Summary 获取真实的源ip

func GetMonthDays

func GetMonthDays(years int, month time.Month) int

GetMonthDays 获取指定年月的天数

func GetNodeID

func GetNodeID(cache cache.ClusterConf, svrName string) int64

func GetNullTime

func GetNullTime(time sql.NullTime) int64

func GetPositionValue added in v0.3.0

func GetPositionValue(position string) (float64, float64)

position 格式: POINT(100.101 50.894)

func GetRandomBase64 added in v0.3.0

func GetRandomBase64(length int) string

func GetSubDay

func GetSubDay(base time.Time, cmp time.Time) int64

GetSubDay 比较两个时间戳差的天数

func Go added in v0.5.1

func Go(ctx context.Context, f func())

func GoNewCtx added in v0.6.0

func GoNewCtx(ctx context.Context, f func(ctx2 context.Context))

func HandleThrow

func HandleThrow(ctx context.Context, p any)

func HmacSha1

func HmacSha1(data string, secret []byte) string

func HmacSha256

func HmacSha256(data string, secret []byte) string

func IndexN added in v0.3.0

func IndexN(src string, c byte, n int) int

从目标串src中查找第n个目标字符c所在位置下标

func Int64ToTimex added in v0.5.1

func Int64ToTimex(in int64) *time.Time

func Ip2binary

func Ip2binary(ip string) string

func IsEmail

func IsEmail(email string) bool

func IsMobile

func IsMobile(mobile string) bool

识别手机号码

func IsNil added in v0.4.1

func IsNil(i interface{}) bool

func MD5V

func MD5V(str []byte) string

func MakePwd

func MakePwd(pwd string, uid int64, isMd5 bool) string

将密码的md5和uid进行md5

func MarshalNoErr added in v0.3.1

func MarshalNoErr(v any) string

func MatchIP

func MatchIP(ip, iprange string) bool

MatchIP 测试IP地址和地址端是否匹配 变量ip为字符串,例子"192.168.56.4" iprange为地址端"192.168.56.64/26"

func Max added in v0.5.1

func Max[t CanAdd](in []t) t

func MethodToNum added in v0.5.1

func MethodToNum(methond string) string

func Min added in v0.5.1

func Min[t CanAdd](in []t) t

func MoonPosition added in v0.5.1

func MoonPosition(t time.Time, lat, lng float64) (float64, float64, float64)

func NewFillPlace added in v0.5.1

func NewFillPlace(num int) string

生成 "?,?,..." (有num个?)

func NewFillSlice added in v0.5.1

func NewFillSlice[T any](num int, val T) []T

func NewFillString added in v0.5.1

func NewFillString(num int, val string, sep string) string

func NullTimeToTime added in v0.5.1

func NullTimeToTime(in sql.NullTime) *time.Time

func PKCS5Padding added in v0.5.1

func PKCS5Padding(src []byte, blockSize int) []byte

func PositionToBaidu added in v0.5.1

func PositionToBaidu(point def.Point) def.Point

func PositionToEarth added in v0.5.1

func PositionToEarth(point def.Point) def.Point

func PrintVersion added in v0.5.1

func PrintVersion()

func Random added in v0.3.0

func Random(length int, level int) string

@in len 密码的长度 @in level 密码的强度级别 0:包含数字和字母 1:包含数字字母和特殊字符

func Recover

func Recover(ctx context.Context)

func ReflectFields added in v0.5.1

func ReflectFields(ptr any, excludeFields []string) []any

解析数据库 表结构字段, ptr:数据表结构, excludeFields:排除的字段名, 返回值:解析出的表结构字段值列表

func SetToSlice added in v0.3.0

func SetToSlice[t constraints.Ordered](in map[t]struct{}) (ret []t)

func SetVal

func SetVal(key any, src, dst any) (num int)

返回修改的数量

func SetVals

func SetVals(src any, dst any) (num int)

func SliceIn added in v0.3.1

func SliceIn[T comparable](in T, cmp ...T) bool

SliceIn 判断 in 是否在 cmp 中

func SliceIndex added in v0.5.1

func SliceIndex[T any](slice []T, index int, defaul T) T

SliceIndex 获取 T[index] 的值,否则返回默认 defaul

func SliceLeftContain added in v0.5.1

func SliceLeftContain[T comparable](bases, childs []T) bool

SliceLeftContain 判断 childs 是否包含在 bases 里(忽略 childs 多出来的值); 如 bases=[1,2,3], childs=[2,3,4],则会返回true;

func SliceLeftDiff added in v0.5.1

func SliceLeftDiff[T comparable](bases, childs []T) []any

SliceLeftDiff 判断 childs 是否包含在 bases 里(忽略 childs 多出来的值); 如 bases=[1,2,3], childs=[2,3,4],则会返回true;

func SliceTo added in v0.4.1

func SliceTo[retT any](values []string, cov func(any) retT) []retT

func SplitCutset added in v0.5.1

func SplitCutset(str, cutset string) []string

SplitCutset 按数组 cuset 里的分隔符,对 str 进行切割

func SqlNullStringToAny added in v0.3.1

func SqlNullStringToAny(in sql.NullString, ret any) error

func SqlToString added in v0.5.1

func SqlToString(val sql.NullString) string

func Sum

func Sum[addT CanAdd](datas ...addT) (sum addT)

func SunPosition added in v0.5.1

func SunPosition(t time.Time, lat, lng float64) (float64, float64)

func SunRiseTime added in v0.5.1

func SunRiseTime(t time.Time, point def.Point) time.Time

太阳升起的时候

func SunSetTime added in v0.5.1

func SunSetTime(t time.Time, point def.Point) time.Time

太阳落下的时候

func SunTimes added in v0.5.1

func SunTimes(t time.Time, point def.Point) map[string]time.Time

calculates sun times for a given date and latitude/longitude

func Time2ToInt64 added in v0.5.1

func Time2ToInt64(t *time.Time) int64

func TimeTo24Sec added in v0.5.1

func TimeTo24Sec(t time.Time) int64

TimeTo24Sec 转换成 24小时的秒单位表示

func TimeToInt64

func TimeToInt64(t time.Time) int64

func TimeToNullTime added in v0.5.1

func TimeToNullTime(in *time.Time) sql.NullTime

func TimeXToTime added in v0.5.1

func TimeXToTime(t *time.Time) time.Time

func ToDefPoint added in v0.5.1

func ToDefPoint(coordinateSystem def.CoordinateSystem, position gocoord.Position) def.Point

func ToEmptyInt64 added in v0.5.1

func ToEmptyInt64(val *wrappers.Int64Value) int64

func ToEmptyString added in v0.5.1

func ToEmptyString(val *wrappers.StringValue) string

func ToMMddHHSS

func ToMMddHHSS(timeStamp int64) string

转换为07-02 01:02 这种格式

func ToNullInt64 added in v0.5.1

func ToNullInt64(val *wrappers.Int64Value) *int64

func ToNullString

func ToNullString(val *wrappers.StringValue) *string

func ToNullTime added in v0.4.1

func ToNullTime(in int64) sql.NullTime

func ToRpcNullDouble added in v0.3.0

func ToRpcNullDouble(val *float64) *wrappers.DoubleValue

func ToRpcNullInt64 added in v0.5.1

func ToRpcNullInt64(val any) *wrappers.Int64Value

func ToRpcNullString

func ToRpcNullString(val any) *wrappers.StringValue

func ToTimeX added in v0.5.1

func ToTimeX(t time.Time) *time.Time

func ToYYMMdd

func ToYYMMdd(timeStamp int64) string

转换为07-02 01:02 这种格式

func ToYYMMddHHSS

func ToYYMMddHHSS(timeStamp int64) string

转换为07-02 01:02 这种格式

func TraceIdFromContext

func TraceIdFromContext(ctx context.Context) string

func TrimNil added in v0.5.1

func TrimNil[a any](in *a) a

func Unmarshal

func Unmarshal(data []byte, v any) error

func UnmarshalNoErr added in v0.5.1

func UnmarshalNoErr[inT any](data string) inT

func VersionCompare added in v0.6.0

func VersionCompare(v1 string, v2 string) int

版本号对比:v1 > v2 ==> 1 或 v1 < v2 ==> -1 或 v1 == v2 ==> 0

Types

type CanAdd

type CanAdd interface {
	constraints.Integer | constraints.Float
}

type CheckExp

type CheckExp interface {
	IsTimeOut() bool
}

type ExpMap

type ExpMap struct {
	Map sync.Map
}

带过期时间的sync.map

func NewExpMap

func NewExpMap(checkTime time.Duration) *ExpMap

type SnowFlake

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

func NewSnowFlake

func NewSnowFlake(mId int64) *SnowFlake

func (*SnowFlake) GetMachineId

func (c *SnowFlake) GetMachineId() int64

获取机器id

func (*SnowFlake) GetSnowflakeId

func (c *SnowFlake) GetSnowflakeId() (id int64)

获取雪花 返回值 id:自增id ts:生成该id的毫秒时间戳

func (*SnowFlake) MilliSecondToTime

func (c *SnowFlake) MilliSecondToTime(milliSecond int64) (t time.Time)

毫秒转换成time

func (*SnowFlake) MillisecondToTimeDb

func (c *SnowFlake) MillisecondToTimeDb(ts int64) string

毫秒转换成"2006-01-02 15:04:05.999"

func (*SnowFlake) MillisecondToTimeTz

func (c *SnowFlake) MillisecondToTimeTz(ts int64) string

毫秒转换成"20060102T150405.999Z"

func (*SnowFlake) ParseId

func (c *SnowFlake) ParseId(id int64) (milliSecond, mId, sn int64)

解析雪花(id) 返回值 milliSecond:毫秒数 mId:机器id sn:序列号

func (*SnowFlake) SetMachineId

func (c *SnowFlake) SetMachineId(mId int64)

设置机器id,默认为0,范围[0,255]

type SunAngle added in v0.5.1

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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