util

package
v0.0.0-...-adb5103 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TimeOffset = 8 * 3600  //8 hour offset
	HalfOffset = 12 * 3600 //Half-day hourly offset
)

Variables

This section is empty.

Functions

func Batch

func Batch[T any, V any](fn func(T) V, ts []T) []V

func BcryptCheck

func BcryptCheck(password, hash string) bool

BcryptCheck 对比明文密码和数据库的哈希值

func BcryptHash

func BcryptHash(password string) string

BcryptHash 使用 bcrypt 对密码进行加密

func Complete

func Complete[E comparable](a []E, b []E) bool

Complete a和b去重后是否相等(忽略顺序)

func Contain

func Contain[E comparable](e E, es ...E) bool

Contain 是否包含

func CopyStructFields

func CopyStructFields(a interface{}, b interface{}, fields ...string) (err error)

copy a by b b->a

func Distinct

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

Distinct 去重

func DistinctAny

func DistinctAny[E any, K comparable](es []E, fn func(e E) K) []E

DistinctAny 去重

func Filter

func Filter[E, T any](es []E, fn func(e E) (T, bool)) []T

func Generate

func Generate() (string, string, string)

Generate 生成验证码

func GenerateUserID

func GenerateUserID() string

生成一个userid

func GenerateUserSig

func GenerateUserSig(ctx context.Context, userID string, sdkAppID int64, key string, expire int64) (string, error)

GenerateUserSig 生成用户签名

func GetBeforeTime

func GetBeforeTime(day int) (int64, string, time.Time)

GetBeforeTime 获取n天前的秒时间戳、日期时间戳 day为负则代表取前几天,为正则代表取后几天,0则为今天

func GetCurDayHalfTimeFormat

func GetCurDayHalfTimeFormat() string

Get the formatted time at 12 o'clock of the day, the format is "2006-01-02_12-00-00"

func GetCurDayHalfTimestamp

func GetCurDayHalfTimestamp() int64

Get the timestamp at 12 o'clock on the day

func GetCurDayZeroTimeFormat

func GetCurDayZeroTimeFormat() string

Get the formatted time at 0 o'clock of the day, the format is "2006-01-02_00-00-00"

func GetCurDayZeroTimestamp

func GetCurDayZeroTimestamp() int64

Get the timestamp at 0 o'clock of the day

func GetCurrentTimestampByMill

func GetCurrentTimestampByMill() int64

Get the current timestamp by Mill

func GetCurrentTimestampByNano

func GetCurrentTimestampByNano() int64

Get the current timestamp by Nano

func GetCurrentTimestampBySecond

func GetCurrentTimestampBySecond() int64

Get the current timestamp by Second

func GetFuncName

func GetFuncName(skips ...int) string

func GetTimeStampByFormat

func GetTimeStampByFormat(datetime string) string

func HashUserID

func HashUserID(userID string) string

哈希 userID

func IndexAny

func IndexAny[E any, K comparable](e E, es []E, fn func(e E) K) int

IndexAny get the index of the element

func IndexOf

func IndexOf[E comparable](e E, es ...E) int

IndexOf get the index of the element

func IsContain

func IsContain(target string, List []string) bool

judge a string whether in the string list

func IsContainInt

func IsContainInt(target int, List []int) bool

func IsContainInt32

func IsContainInt32(target int32, List []int32) bool

func Keys

func Keys[K comparable, V any](kv map[K]V) []K

Keys get map keys

func Md5

func Md5(s string, salt ...string) string

func NewTimestamp

func NewTimestamp(t time.Time) *timestamppb.Timestamp

func Single

func Single[E comparable](a, b []E) []E

Single a中存在,b中不存在 或 b中存在,a中不存在

func Slice

func Slice[E any, T any](es []E, fn func(e E) T) []T

Slice 批量转换切片类型

func SliceSet

func SliceSet[E comparable](es []E) map[E]struct{}

SliceSet slice to map[E]struct{}

func SliceSetAny

func SliceSetAny[E any, K comparable](es []E, fn func(e E) K) map[K]struct{}

SliceSetAny slice to map[K]struct{}

func SliceToMap

func SliceToMap[E any, K comparable](es []E, fn func(e E) K) map[K]E

SliceToMap slice to map

func SliceToMapAny

func SliceToMapAny[E any, K comparable, V any](es []E, fn func(e E) (K, V)) map[K]V

SliceToMapAny slice to map (自定义类型)

func SliceToMapOkAny

func SliceToMapOkAny[E any, K comparable, V any](es []E, fn func(e E) (K, V, bool)) map[K]V

SliceToMapOkAny slice to map (自定义类型, 筛选)

func Sort

func Sort[E Ordered](es []E, asc bool) []E

Sort basic type sorting

func SortAny

func SortAny[E any](es []E, fn func(a, b E) bool)

SortAny custom sort method

func Split2Int64Slice

func Split2Int64Slice(s string) []int64

func TimeNow

func TimeNow() *time.Time

func TimeStampChangeTimeStr

func TimeStampChangeTimeStr(timeStamp int64) string

时间戳转时间字符串

func TimeStringFormatTimeTime

func TimeStringFormatTimeTime(timeFormat string, timeSrc string) time.Time

func TimeStringFormatTimeUnix

func TimeStringFormatTimeUnix(timeFormat string, timeSrc string) int64

func TimeStringToTime

func TimeStringToTime(timeString string) (time.Time, error)

func TimeStringToTimeTime

func TimeStringToTimeTime(timeSrc string) time.Time

func TimeToString

func TimeToString(t time.Time) string

func TimestampToTime

func TimestampToTime(t *timestamppb.Timestamp) time.Time

func UnixMillSecondToTime

func UnixMillSecondToTime(millSecond int64) time.Time

func UnixNanoSecondToTime

func UnixNanoSecondToTime(nanoSecond int64) time.Time

Convert nano timestamp to time.Time type

func UnixSecondToTime

func UnixSecondToTime(second int64) time.Time

Convert timestamp to time.Time type

func Values

func Values[K comparable, V any](kv map[K]V) []V

Values get map values

func Verify

func Verify(id string, val string) bool

Verify 验证验证码

Types

type Cache

type Cache[T comparable, K any] interface {
	Get(T) (K, error)
	MustGet(T) K
}

func NewCache

func NewCache[T comparable, K any](fn func(T) (K, error)) Cache[T, K]

type GoogleAuth

type GoogleAuth struct {
}

func NewGoogleAuth

func NewGoogleAuth() *GoogleAuth

func (*GoogleAuth) GetCode

func (this *GoogleAuth) GetCode(secret string) (string, error)

GetCode 获取动态码

func (*GoogleAuth) GetQrcode

func (this *GoogleAuth) GetQrcode(secret string) string

GetQrcode 获取动态码二维码内容

func (*GoogleAuth) GetQrcodeUrl

func (this *GoogleAuth) GetQrcodeUrl(secret string) string

GetQrcodeUrl 获取动态码二维码图片地址,这里是第三方二维码api

func (*GoogleAuth) GetSecret

func (this *GoogleAuth) GetSecret() string

GetSecret 获取秘钥

func (*GoogleAuth) VerifyCode

func (this *GoogleAuth) VerifyCode(secret, code string) (bool, error)

VerifyCode 验证动态码

type Ordered

type Ordered interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64 | ~string
}

Ordered types that can be sorted

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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