idgen

package
v0.0.0-...-012d1c6 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: Apache-2.0 Imports: 0 Imported by: 0

README

ID生成器

这里提供了几种ID生成方法

xid

类似mongodb的产生方式,零配置,ID有序,二进制占用12个bytes,字符串占用20个char

[tid]

基于时间戳和自增序列的id生成器,类似于snowflake,vesta-id-generator,生成的ID是一个uint64的整数, 支持uint64,支持秒,毫秒两种模式,集群需要配置nodeId才能避免重复,毫秒模式需要注意时间回调会导致ID重复而报错 id粗略有序

[sid]

shortid,生成的ID是字符串格式,无序并随机,不可以反解析,相比较teris-io/shortid,这里支持了base32,所有字段都参与随机 参考: shortid go-shortid

[redeem]兑换码生成

要求生成的兑换码随机,无序,不易猜测,易输入,可逆可验证,兑换码中通常会包含一个ID信息

其他算法

  • luhn 模10校验算法

Documentation

Index

Constants

View Source
const (
	Alphabet32 = "0123456789bcdefghjkmnpqrstuvwxyz"
	Alphabet64 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-"
)

Variables

This section is empty.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
alg

Jump to

Keyboard shortcuts

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