utils

package
v0.0.0-...-435223f Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NanosecondsInAMillisecond = 1_000_000 // 每毫秒的纳秒数
	MillisecondsInASecond     = 1000      // 每秒的毫秒数
)
View Source
const DefaultFilePermissions = 0o666 // 默认文件权限
View Source
const StuIDLen = 23

Variables

This section is empty.

Functions

func AddrCheck

func AddrCheck(addr string) bool

AddrCheck 会检查当前的监听地址是否已被占用

func CheckImageFileType

func CheckImageFileType(header *multipart.FileHeader) (string, bool)

CheckImageFileType 检查文件格式是否合规

func CheckPwd

func CheckPwd(pwd string) bool

func FileToByteArray

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

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

func GenerateRedisKeyByStuId

func GenerateRedisKeyByStuId(stuId string, sType int64, device string) string

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

func GetAvailablePort

func GetAvailablePort() (string, error)

GetAvailablePort 会尝试获取可用的监听地址

func GetDeviceID

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

GetDeviceID 获取数据中心ID和机器ID

func GetEsHost

func GetEsHost() (string, error)

GetEsHost 会获取 ElasticSearch 的客户端

func GetGenTime

func GetGenTime(sid int64) (t string)

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

func GetGenTimestamp

func GetGenTimestamp(sid int64) (timestamp int64)

GetGenTimestamp 获取创建ID时的时间戳

func GetImageFileType

func GetImageFileType(fileBytes *[]byte) (string, error)

GetImageFileType 获得图片格式

func GetMysqlDSN

func GetMysqlDSN() (string, error)

GetMysqlDSN 会拼接 mysql 的 DSN

func GetTimestamp

func GetTimestamp(sid int64) (timestamp int64)

GetTimestamp 获取时间戳

func GetTimestampStatus

func GetTimestampStatus() (state float64)

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

func HandleBaseRespWithCookie

func HandleBaseRespWithCookie(baseResp *model.BaseResp) error

HandleBaseRespWithCookie 调用jwch库的接口的结果处理, 将 resp.Base 中包含的错误转换成 errno 类型

func HrefEncode

func HrefEncode(rawQuery string) string

HrefEncode 解析rawQuery以获得未解码的url(hertz会自动解析未解码的url)

func IsSuccess

func IsSuccess(baseResp *model.BaseResp) bool

IsSuccess 通用的rpc结果处理

func JSONEncode

func JSONEncode(v interface{}) (string, error)

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 这里只能解析这样的数组: "Key=Value; Key=Value"

func ParseCookiesToString

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

ParseCookiesToString 会尝试解析 cookies 到 string 只会返回 "Key=Value; Key=Value"样式的文本数组

func ParseJwchStuId

func ParseJwchStuId(id string) (string, error)

ParseJwchStuId 用于解析教务处 id 里的学号 如 20241025133150102401339 的后 9 位

func RetryLogin

func RetryLogin(stu *jwch.Student) error

RetryLogin 将会重新尝试进行登录

func SHA256

func SHA256(str string) string

SHA256 use sha256 to encode string

func TimeParse

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

TimeParse 会将文本日期解析为标准时间对象

func UriEncode

func UriEncode(uri string) string

Types

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