uuidx

package
v0.0.0-...-69bdcc1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package uuidx 是 uuid 的升级版,用于生成全局唯一且趋势递增的ID 抛弃了云时代虚拟的机器码、IP地址、进程ID等元素,只使用时间+60位真随机数,简单可靠 10进制最长31数位,用Mysql的Decimal长度14字节,字符串使用36进制可压缩到20字符 可以生成以日期时间字面值开头的ID,适合人机交互的场景,如订单ID、日志ID等 使用方法: NewId().Bigint() 生成全局唯一且趋势递增的ID,如:1929739840127008107666424440799 NewId().Bigint().Text(36) 生成全局ID并压缩为36进制字符串,如:573aeu9097046yj2zgx0 NewId().TimeLike() 生成以日期时间字面值开头的ID,如:20230115200352645112789402627768

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Id

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

func NewId

func NewId() Id

func NewIdWithTime

func NewIdWithTime(t time.Time) Id

func ParseBigint

func ParseBigint(i *big.Int) Id

func ParseTimeLike

func ParseTimeLike(i *big.Int) Id

func (Id) Bigint

func (id Id) Bigint() *big.Int

Bigint 使用Unix时间毫秒+60位随机数 10进制31位上限至2244年,用Mysql的Decimal长度14字节 16进制26位上限至2527年,36进制20位上限至2337年

func (Id) Int63

func (id Id) Int63() int64

Int63 高33位为时间秒,上限为2242-03-16,并发太高可能存在重复

func (Id) Rand

func (id Id) Rand() *big.Int

func (Id) Time

func (id Id) Time() time.Time

func (Id) TimeLike

func (id Id) TimeLike() *big.Int

TimeLike 使用10进制时的年月日时分秒+60位随机数 适用于订单号、日志ID等,9999年之前都是32位10进制

Jump to

Keyboard shortcuts

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