luid

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package luid implements IDs that are (practically always) sequential but are not iterative like auto incrementing IDs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ID

type ID [12]byte

ID is an array of 12 bytes that is composed of 8 bytes of time and 4 random bytes in big endian byte order.

func FromString

func FromString(hex string) (id ID, err error)

FromString unmarshals hex and returns an ID.

hex can be any valid hexadecimal number of len(ID) bytes. FromString does not check whether hex corrosponds to a valid ID.

func New

func New() (ID, time.Time)

New returns a new ID and the time.Time (current time in UTC) used for the first 8 bytes of ID.

Remember to call rand.Seed before using New.

func (ID) EqualsTo

func (d ID) EqualsTo(x ID) bool

EqualsTo returns true if d and x are identical byte strings.

func (ID) MarshalText

func (d ID) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler interface. And returns the hexadecimal encoding of ID.

func (*ID) Scan

func (d *ID) Scan(src interface{}) error

Scan implements sql.Scanner interface.

func (ID) String

func (d ID) String() string

String returns the hexadecimal encoding of ID.

func (*ID) UnmarshalText

func (d *ID) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler interface. text is supposed to be the hexadecimal encoding of an ID.

func (ID) Value

func (d ID) Value() (driver.Value, error)

Value implements driver.Valuer interface.

func (*ID) Zero

func (d *ID) Zero()

Zero sets all bytes of ID to 0.

type NullID

type NullID struct {
	ID    ID
	Valid bool
}

NullID represents an ID that may be null. It is identical to sql.NullString.

func (NullID) MarshalJSON

func (ni NullID) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshalar interface.

func (*NullID) Scan

func (ni *NullID) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (*NullID) UnmarshalJSON

func (ni *NullID) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshalar interface.

func (NullID) Value

func (ni NullID) Value() (driver.Value, error)

Value implements driver.Valuer interface.

Jump to

Keyboard shortcuts

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