snowflake

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

利用雪花算法,生成分布式唯一ID

    id := ID()
fmt.Println(id, ServerId(id))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ID

func ID() string

func IDInt64 added in v1.1.4

func IDInt64() int64

func ServerId

func ServerId(snowId string) int64

ServerId 根据生成的snowId计算出机器ID

Types

type Node

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

A Node struct holds the basic information needed for a snowflake generator

func NewNode

func NewNode(node int64) (*Node, error)

NewNode returns a new snowflake node that can be used to generate snowflake IDs 参数为机器ID 机器注册中心ID

func (*Node) NextIdInt64

func (n *Node) NextIdInt64() int64

NextIdInt64 返回ID的int64形式

func (*Node) NextIdStr

func (n *Node) NextIdStr() string

NextIdStr 返回ID的字符串形式

Jump to

Keyboard shortcuts

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