Flake

package
v0.0.0-...-e11b555 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMachineIdentification

func GetMachineIdentification() (uint16, error)

* @brief: 根据本机网卡MAC地址和随机数拼出一个16位的机器标识 * @notes: sony的雪花算法库默认的生成机器标示函数是使用内网IP算的,因为客户端在调用这个函数,现在基本都使用NET技术,很可能出现重复,所以需要修改生成机器标识函数. * 目前打算前6位为分别为mac地址六项的第一个数的最后一位之间互相异或,后十位为随机值,因为还有时间戳位,这样可以最大化保证全局不会出现唯一ID,但是其实还是有可能. * 且因为同一个主机生成的机器标示肯定还是一样的,所以测试代码还是只能手动改UUID.

func GetSonyflake

func GetSonyflake() uint64
  • @brief: 通过雪花算法生成一个全局唯一的ID
  • @notes: 在协议层使用0作为初始值,显然使用flake生成的uuid不可能为零,因为时间戳已经设置好了

ps:测试代码出现问题的原因很简单,就是时间戳可能是一样的,这其实没什么好办法,测试代码手工配置最方便。

Types

This section is empty.

Jump to

Keyboard shortcuts

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