utils

package
v0.0.0-...-c54bc52 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2025 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const SaltSize = 16

Variables

View Source
var ServerIP = ""

Functions

func CopyStructFields

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

func Date

func Date() string

func Date2Second

func Date2Second(date string) int64

func DateTime

func DateTime() string

func DateTime2Second

func DateTime2Second(datetime string) int64

func DoPasswordsMatch

func DoPasswordsMatch(hashedPassword, currPassword string,
	salt []byte) bool

func EncryptPassword

func EncryptPassword(data []byte) (res string)

func GenerateToken

func GenerateToken(uid string) (string, int64, error)

func GetSwitchFromOptions

func GetSwitchFromOptions(Options map[string]bool, key string) (result bool)

func GetUserId

func GetUserId(token string) (string, error)

func HashPassword

func HashPassword(password string, salt []byte) string

func Int64ToString

func Int64ToString(i int64) string

func IntToString

func IntToString(i int) string

func InterfaceArrayToStringArray

func InterfaceArrayToStringArray(data []interface{}) (i []string)

func IsContain

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

judge a string whether in the string list

func JsonStringToMap

func JsonStringToMap(str string) (tempMap map[string]int32)

func JsonStringToStruct

func JsonStringToStruct(s string, args interface{}) error

The incoming parameter must be a pointer

func MapIntToJsonString

func MapIntToJsonString(param map[string]int32) string

func MapToJsonString

func MapToJsonString(param map[string]interface{}) string

func MarshalGob

func MarshalGob(data interface{}) ([]byte, error)

func NowMilliSecond

func NowMilliSecond() int64

func NowSecond

func NowSecond() int64

func NowSecondWithLocation

func NowSecondWithLocation(name string) int64

NowSecondWithLocation ex. NowSecondWithLocation("Asia/Shanghai")

func Perm

func Perm(n int) []int

Perm 返回半开区间 [0,n) 内整数伪随机排列

func RandFloat64

func RandFloat64() float64

RandFloat64 从 [0.0, 1.0] 中获取随机数

func RandIntN

func RandIntN(n int) int

RandIntN 从 [0, n) 随机获取一个整数

func RandIntRange

func RandIntRange(min, max int) int

RandIntRange 从 [min, max) 中随机获取一个整数

func RandNormFloat64

func RandNormFloat64() float64

RandNormFloat64 从均值为0, 标准差为1的正态分布获取随机浮点数

func RandNormFloat64WithMeanStddev

func RandNormFloat64WithMeanStddev(mean, stddev float64) float64

RandNormFloat64WithMeanStddev 从均值为mean, 标准差为stddev 的正态分布中获取随机浮点数

func RandomSalt

func RandomSalt() []byte

func Second2Date

func Second2Date(second int64) string

func Second2DateTime

func Second2DateTime(second int64) string

func SetSwitchFromOptions

func SetSwitchFromOptions(options map[string]bool, key string, value bool)

func Shuffle

func Shuffle[T any](slice []T)

Shuffle 打乱数组中元素的顺序

func StringToInt

func StringToInt(i string) int

func StringToInt32

func StringToInt32(i string) int32

func StringToInt64

func StringToInt64(i string) int64

func StructToJsonString

func StructToJsonString(param interface{}) string

func UnmarshalGob

func UnmarshalGob(data []byte, res interface{}) error

func UnmarshalJson

func UnmarshalJson(data []byte, config interface{}, errorOnUnmatchedKeys bool) (err error)

func UnmarshalYaml

func UnmarshalYaml(data []byte, config interface{}, errorOnUnmatchedKeys bool) (err error)

func VerifyToken

func VerifyToken(tokenString, uid string) bool

Types

type Claims

type Claims struct {
	UID      string
	Platform int32
	jwt.RegisteredClaims
}

func BuildClaims

func BuildClaims(uid string, ttl int64) Claims

func ParseToken

func ParseToken(tokenString string) (*Claims, error)

type Map

type Map struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Map) Del

func (m *Map) Del(key interface{})

func (*Map) Get

func (m *Map) Get(key interface{}) interface{}

func (*Map) Len

func (m *Map) Len() int

func (*Map) LockRange

func (m *Map) LockRange(f func(interface{}, interface{}))

func (*Map) RLockRange

func (m *Map) RLockRange(f func(interface{}, interface{}))

func (*Map) Set

func (m *Map) Set(key interface{}, value interface{})

func (*Map) TestAndSet

func (m *Map) TestAndSet(key interface{}, value interface{}) interface{}

func (*Map) UnsafeDel

func (m *Map) UnsafeDel(key interface{})

func (*Map) UnsafeGet

func (m *Map) UnsafeGet(key interface{}) interface{}

func (*Map) UnsafeLen

func (m *Map) UnsafeLen() int

func (*Map) UnsafeRange

func (m *Map) UnsafeRange(f func(interface{}, interface{}))

func (*Map) UnsafeSet

func (m *Map) UnsafeSet(key interface{}, value interface{})

Jump to

Keyboard shortcuts

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