utils

package
v0.0.0-...-2d1efbd Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddrCheck

func AddrCheck(addr string) bool

func CreateToken

func CreateToken(userId int64) (string, error)

func FileToByteArray

func FileToByteArray(file *multipart.FileHeader) (fileBuf [][]byte, err error)

FileToByteArray 用于将客户端发来的文件转换为[][]byte格式,用于流式传输

func GenerateRedisKeyByStuId

func GenerateRedisKeyByStuId(stuId int64, sType int64) string

GenerateRedisKeyByStuId 开屏页通过学号与sType生成缓存对应Key

func GetAvailablePort

func GetAvailablePort() (string, error)

func GetDeviceID

func GetDeviceID(sid int64) (datacenterid, workerid int64)

获取数据中心ID和机器ID

func GetEsHost

func GetEsHost() (string, error)

func GetGenTime

func GetGenTime(sid int64) (t string)

获取创建ID时的时间字符串(精度:秒)

func GetGenTimestamp

func GetGenTimestamp(sid int64) (timestamp int64)

获取创建ID时的时间戳

func GetMysqlDSN

func GetMysqlDSN() (string, error)

func GetTimestamp

func GetTimestamp(sid int64) (timestamp int64)

获取时间戳

func GetTimestampStatus

func GetTimestampStatus() (state float64)

获取时间戳已使用的占比:范围(0.0 - 1.0)

func IsAllowImageFile

func IsAllowImageFile(header *multipart.FileHeader) bool

IsAllowImageFile 检查文件格式是否合规,支持jpg png jpeg格式

func IsSuccess

func IsSuccess(baseResp *model.BaseResp) bool

IsSuccess 通用的rpc结果处理

func LoadCNLocation

func LoadCNLocation() *time.Location

LoadCNLocation 载入cn时间

func MD5

func MD5(str string) string

MD5 use md5 to encode string

func MD5Bytes

func MD5Bytes(str []byte) string

func ParseCookies

func ParseCookies(rawData []string) []*http.Cookie

ParseCookies 将cookie字符串解析为http.Cookie

func ParseCookiesToString

func ParseCookiesToString(cookies []*http.Cookie) []string

func RetryLogin

func RetryLogin(stu *jwch.Student) error

func SHA256

func SHA256(str string) string

SHA256 use sha256 to encode string

func SaveImageFromBytes

func SaveImageFromBytes(imgBytes []byte, format string) error

SaveImageFromBytes 仅用于测试流式传输结果是否正确

func TimeParse

func TimeParse(date string) (time.Time, error)

Types

type Claims

type Claims struct {
	UserId int64 `json:"user_id"`
	jwt.StandardClaims
}

func CheckToken

func CheckToken(token string) (*Claims, error)

type Snowflake

type Snowflake struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewSnowflake

func NewSnowflake(datacenterid, workerid int64) (*Snowflake, error)

func (*Snowflake) NextVal

func (s *Snowflake) NextVal() (int64, error)

timestamp + 数据中心id + 工作节点id + 自旋id

Jump to

Keyboard shortcuts

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