utils

package
v0.0.0-...-ccdcda8 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

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 CheckToken

func CheckToken(token string) (int64, int64, error)

CheckToken 检查 token 是否有效,并返回 token 类型和用户 ID

func CreateAllToken

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

CreateAllToken 创建一对 token,第一个是 access token,第二个是 refresh token

func CreateToken

func CreateToken(tokenType int64, uid int64) (string, error)

CreateToken 根据 token 类型和用户 ID 创建 token

func FileToBytes

func FileToBytes(file *multipart.FileHeader) (ret [][]byte, err error)

func GenerateFileName

func GenerateFileName(path string, id int64) string

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 GetFloat64

func GetFloat64(d *decimal.Decimal) float64

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 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 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 Claims

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

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