snowflake

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2023 License: MIT Imports: 11 Imported by: 0

README

snowflake

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultNode = MustNew()

DefaultNode 默认阶段

Functions

func NewOptions

func NewOptions() *options

NewOptions new options struct

func PrintOptions

func PrintOptions(packageName string)

Types

type ID

type ID uint64

func Alloc

func Alloc(step uint64) (ID, error)

func Gen

func Gen() (ID, error)

func MustAlloc

func MustAlloc(step uint64) ID

func MustGen

func MustGen() ID

func (ID) Base32

func (i ID) Base32() string

func (ID) Base32Lower

func (i ID) Base32Lower() string

func (ID) Hex

func (i ID) Hex() string

func (ID) IsGlobal

func (i ID) IsGlobal(n *Node) bool

func (ID) Node

func (i ID) Node(n *Node) uint64

func (ID) Step

func (i ID) Step(n *Node) uint64

func (ID) String

func (i ID) String() string

func (ID) Time

func (i ID) Time(n *Node) time.Time

func (ID) Uint64

func (i ID) Uint64() uint64

func (ID) UnixMilli

func (i ID) UnixMilli(n *Node) int64

type Node

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

func MustNew

func MustNew(_opts ...Option) *Node

MustNew must constructor, it will panic if error not nil

func New

func New(_opts ...Option) (*Node, error)

New constructor

func (*Node) Alloc

func (n *Node) Alloc(step uint64) (ID, error)

func (*Node) Gen

func (n *Node) Gen() (ID, error)

func (*Node) MustAlloc

func (n *Node) MustAlloc(step uint64) ID

func (*Node) MustGen

func (n *Node) MustGen() ID

func (*Node) NodeBits

func (n *Node) NodeBits() uint8

func (*Node) SetOptions

func (_n *Node) SetOptions(_opts ...Option) *Node

func (*Node) StepBits

func (n *Node) StepBits() uint8

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option option interface

func SkipOption

func SkipOption() Option

func WithEpoch

func WithEpoch(epoch time.Time) Option

WithEpoch epoch option of Node

func WithGlobalFlag

func WithGlobalFlag(globalFlag bool) Option

WithGlobalFlag globalFlag option of Node

func WithNode

func WithNode(node uint64) Option

WithNode node option of Node

func WithNodeBits

func WithNodeBits(nodeBits uint8) Option

WithNodeBits nodeBits option of Node

func WithOptions

func WithOptions(o *options) Option

func WithStorage

func WithStorage(storage Storage) Option

WithStorage storage option of Node

type Storage

type Storage interface {
	Get() (t int64, err error)
	Save(t int64) error
}

Directories

Path Synopsis
storage

Jump to

Keyboard shortcuts

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