uniqueid

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2023 License: MIT Imports: 6 Imported by: 0

README

生成全局唯一ID

示例:

func TestGetUniqueID(t *testing.T) {
	err := Register()
	if err != nil {
		t.Error(err)
	}

	nodeMap := make(map[int64]int)
	for i := 1; i < 10000; i++ {
		uniqueID := New().Number()
		if id, ok := nodeMap[uniqueID]; ok {
			t.Error(id)
		} else {
			nodeMap[uniqueID] = i
		}
	}
  t.Log()
}

todo

当前生成的上一个数字形式的全局id,以后待补充一个UUID

实现UUID可参考https://github.com/google/uuid

北京时间2021年10月08日00:06:42,UUID暂时不考虑做入这个包内,也许会直接使用Google的包

ref. Copied from houzhenkai

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IP

func IP() string

func NodeID

func NodeID() int64

func Number

func Number() int64

func Register

func Register(options ...Option) error

NewNode 实例化一个工作节点 优先级是: 传入参数 > 已存在的NodeID > createNodeID

func String

func String() string

Types

type Node

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

Node 定义一个Node工作节点所需要的基本参数

type Option

type Option struct {
	NodeID int64
}

Jump to

Keyboard shortcuts

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