xid

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: MIT Imports: 13 Imported by: 11

Documentation

Index

Constants

View Source
const (
	MaxDataNode = kMaxDataNode
)

Variables

View Source
var (
	ErrDataNodeNotAllowed = errors.New(fmt.Sprintf("xid: data node can't be greater than %d or less than 0", kMaxDataNode))
)

Functions

func DataNode

func DataNode(s int64) int64

DataNode 获取 id 的数据节点标识

func Init

func Init(opts ...Option) (err error)

func IsMIDHex

func IsMIDHex(s string) bool

func Next

func Next() int64

func Sequence

func Sequence(s int64) int64

Sequence 获取 id 的序列号

func Time

func Time(s int64) int64

Time 获取 id 的时间,单位是 second

Types

type MID

type MID string

MID 从 mgo.bson 复制

func MIDHex

func MIDHex(s string) MID

func NewMID

func NewMID() MID

func (MID) Counter

func (m MID) Counter() int32

func (MID) Hex

func (m MID) Hex() string

func (MID) Machine

func (m MID) Machine() []byte

func (MID) MarshalJSON

func (m MID) MarshalJSON() ([]byte, error)

func (MID) MarshalText

func (m MID) MarshalText() ([]byte, error)

func (MID) Pid

func (m MID) Pid() uint16

func (*MID) Scan

func (m *MID) Scan(value interface{}) (err error)

func (MID) String

func (m MID) String() string

func (MID) Time

func (m MID) Time() int64

func (*MID) UnmarshalJSON

func (m *MID) UnmarshalJSON(data []byte) error

func (*MID) UnmarshalText

func (m *MID) UnmarshalText(data []byte) error

func (MID) Valid

func (m MID) Valid() bool

func (MID) Value

func (m MID) Value() (driver.Value, error)

type Option

type Option func(*XID) error

func WithDataNode

func WithDataNode(node int64) Option

WithDataNode 设置数据节点标识

func WithTimeOffset

func WithTimeOffset(t time.Time) Option

WithTimeOffset 设置时间偏移量

type XID

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

func Default

func Default() *XID

func New

func New(opts ...Option) (*XID, error)

func (*XID) DataNode

func (x *XID) DataNode() int64

func (*XID) Next

func (x *XID) Next() int64

func (*XID) TimeOffset

func (x *XID) TimeOffset() int64

Directories

Path Synopsis
etcd module
examples Module
zookeeper module
examples Module

Jump to

Keyboard shortcuts

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