fastid

package
v1.3.6 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 4 Imported by: 0

README

订单号-生成算法

基于 snowflake 算法,根据业务场景,做适应性调整:

block说明 bits 拟采用的实现方式
1 最高位 1 暂未使用(置0)
2 时间戳 28 采用unix 毫秒数 (millsOfDay) bin(24x60x60x1000) = '0b101-0010-0110-0101-1100-0000-0000' 需要27bit
3 机器ID 8 为支持分布式,加入机器ID。现阶段机器不会太多,可采用1个字节标识(如采用机器IP最后2字节,异或为1个字节)
4 管理员ID 8 取管理员ID低 8位
5 用户ID 8 取用户ID 低8位

最后,在订单编号上加上 8 个数字的日期前缀:YYYYMMDD

orderSN 总长度为27位数字(8+19),样例: 202105171838043898712414209 PS:int64 格式化为19位的10进制数,不足19位补充前缀0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StdFastID = NewFastID()

StdFastID 默认的fastID

Functions

func GetMachineByIP

func GetMachineByIP(strIP string) byte

GetMachineByIP 获取机器ID (IP最后2字节异或)

func GetMachineFromID

func GetMachineFromID(id int64) byte

GetMachineFromID 从ID中获取machineID

func GetSeqFromID

func GetSeqFromID(id int64) int64

GetSeqFromID 从ID中获取seq

func GetTimeFromID

func GetTimeFromID(id int64) int64

GetTimeFromID 从ID中获取time

func LSB

func LSB(v uint) byte

LSB last byte

Types

type FastID

type FastID struct {
	// contains filtered or unexported fields
}

FastID 分布式唯一ID

func NewFastID

func NewFastID() *FastID

NewFastID new

func (*FastID) GenID

func (f *FastID) GenID(operatorID, userID uint) string

GenID 生成唯一ID (格式:YYYYMMDD+ID,27位数字)

Jump to

Keyboard shortcuts

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