Documentation ¶
Index ¶
- Variables
- func NewCustomizedNanoId(alphabet string, size int) (string, error)
- func NewCustomizedULID(ms uint64, entropy io.Reader) (string, error)
- func NewNanoId(l ...int) (string, error)
- func NewSimpleUUID() string
- func NewSonyFlake(settings *sonyflake.Settings) (*sonyflake.Sonyflake, error)
- func NewULID() string
- func NewUUID() stringdeprecated
- func NewXid() string
- func NewXidWithTime(t time.Time) string
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func NewCustomizedNanoId ¶
NewCustomizedNanoId 生成定制化的NanoId
@param alphabet 字母表(默认为"_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") @param size 生成NanoId字符串的长度
func NewNanoId ¶
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 ¶
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 NewXid ¶
func NewXid() string
NewXid Xid是一个全局唯一的ID生成器,它使用Mongo Object ID算法来生成全局唯一的ID.
PS: (1) 单进程内生成唯一id,推荐使用 xid. (2) 一个进程(Process)内,生成的id不会重复.
@return 长度固定为20
e.g.
"ckic7hfnl531vbl645n0" "ckth51co47mgs2kacmk0"
func NewXidWithTime ¶
Types ¶
This section is empty.