idKit

package
v2.9.114 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCustomizedNanoId

func NewCustomizedNanoId(alphabet string, size int) (string, error)

NewCustomizedNanoId 生成定制化的NanoId

@param alphabet 字母表(默认为"_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") @param size 生成NanoId字符串的长度

func NewCustomizedULID

func NewCustomizedULID(ms uint64, entropy io.Reader) (string, error)

func NewNanoId

func NewNanoId(l ...int) (string, error)

NewNanoId 生成NanoId

NanoID 了解一下?比 UUID 更好用! - https://mp.weixin.qq.com/s/4muEuUkk3tq6iJXLwspQyQ

@param l 生成NanoId字符串的长度,不传参则默认长度为21(!!!:传参个数只能为0或1,且值>=0) @return 返回值的字母表为: "_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

e.g. () => ("4spQ-UdpjbhSjE046w1Ij", nil)

func NewSimpleUUID

func NewSimpleUUID() string

NewSimpleUUID UUIDv4,去掉了其中所有"-"

@return 长度32

e.g.

() => "415ef754dc174b888b186873e093ced1"

func NewSonyFlake

func NewSonyFlake(settings *sonyflake.Settings) (*sonyflake.Sonyflake, error)

NewSonyFlake 雪花算法.

PS: (1) 可用作分布式唯一id(前提是合理配置好 MachineID); (2) 通过 sonyflake.Sonyflake.NextID() 生成id(貌似是18位的).

golang实现的雪花算法 https://mp.weixin.qq.com/s/visG_GHtU67xCtsvvG1aPQ

@param settings 可以为nil(但不推荐这么干)

func NewULID

func NewULID() string

NewULID ULID(不建议用作分布式唯一id,小概率会重复)

PS: (1) 重复概率非常低,但不建议用作分布式唯一id(可以用作本地唯一id). (2) Format: tttttttttteeeeeeeeeeeeeeee where t is time and e is entropy.(时间+随机数) (3) If you just want to generate a ULID and don't (yet) care about details like performance, cryptographic security, etc., use the ulid.Make helper function.

This function calls time.Now to get a timestamp, and uses a source of entropy which is process-global, pseudo-random, and monotonic.

@return 长度: 26(即 ulid.EncodedSize)

e.g. () => "01GMSRXRWJPYSQQZ5Z6T832CSZ"

func NewUUID deprecated

func NewUUID() string

NewUUID UUIDv4

Deprecated: use NewULID instead.

PS: 重复概率非常低,不建议用作分布式唯一id.

@return 长度36

e.g.

() => "936eff5f-97c6-4f8b-b26d-9bab1f65ff55"

func NewXid added in v2.2.58

func NewXid() string

NewXid Xid是一个全局唯一的ID生成器,它使用Mongo Object ID算法来生成全局唯一的ID.

PS: (1) 单进程内生成唯一id,推荐使用 xid. (2) 一个进程(Process)内,生成的id不会重复.

@return 长度(len())固定为20

e.g.

"ckic7hfnl531vbl645n0"
"ckth51co47mgs2kacmk0"

func NewXidWithTime added in v2.9.104

func NewXidWithTime(t time.Time) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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