Documentation
¶
Index ¶
- Constants
- func CheckPassword(hashedPassword, password string) error
- func GenerateRandomString(length int) (string, error)
- func GetUserID(ctx context.Context) string
- func GetUserName(ctx context.Context) string
- func HashPassword(password string) (string, error)
- func NewContext(ctx context.Context, userID, userName string) context.Context
- func SetUserID(ctx context.Context, userID string) context.Context
- func SetUserName(ctx context.Context, userName string) context.Context
- type Sonyflake
Constants ¶
View Source
const ( USER_ID = contextKey("x-user-id") USER_NAME = contextKey("x-user-name") AUTH_ERROR = contextKey("x-auth-error") ACCESS_TOKEN = contextKey("access-token") REFRESH_TOKEN = contextKey("refresh-token") )
Variables ¶
This section is empty.
Functions ¶
func CheckPassword ¶
CheckPassword 比对哈希 @param hashedPassword 存储的哈希 @param password 输入的密码 @return error 错误
func GenerateRandomString ¶
generateRandomString 生成随机字符串 length: 返回字符串长度
func GetUserName ¶
func HashPassword ¶
HashPassword 加盐哈希 @param password 输入的密码 @return string 存储的哈希 @return error 错误
Types ¶
type Sonyflake ¶
type Sonyflake struct {
// contains filtered or unexported fields
}
Sonyflake 是基于Sonyflake算法的分布式ID生成器 特点:
- 分布式:支持在多个节点上生成唯一ID
- 趋势递增:生成的ID总体趋势是递增的
- 高性能:无锁设计,生成速度快
- 时间有序:ID中包含时间戳信息,可按时间排序
ID结构:1位保留 + 39位时间戳 + 8位机器ID + 16位序列号 适用于分布式系统、数据库主键等场景
func NewSonyflake ¶
func NewSonyflake() *Sonyflake
NewSonyflake 创建并返回一个新的Sonyflake实例 使用默认配置初始化Sonyflake生成器 默认配置使用内网IP地址作为机器ID的生成依据 返回:初始化好的Sonyflake实例指针
func (*Sonyflake) GenerateID ¶
GenerateID 生成一个唯一的分布式ID 如果ID生成过程中发生错误,会触发panic 返回:64位的唯一ID
Click to show internal directories.
Click to hide internal directories.