uid

package
v0.0.0-...-db3ccfa Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

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 supposed to be composed of 8 bytes of time (number of nanoseconds elapsed since January 1, 1970 UTC) and 4 random bytes.

func From

func From(ts uint64, rand uint32) ID

From returns an ID with ts timestamp in the first 8 bytes and rand in the last 4 bytes.

func FromString

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

FromString unmarshals hex into id.

hex can be any valid hexadecimal number corresponding to len(id) bytes.

func New

func New() ID

New returns a new id.

func (ID) Bytes

func (d ID) Bytes() []byte

func (*ID) Clear

func (d *ID) Clear()

Clear sets all bytes of d to 0.

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) Time

func (d ID) Time() time.Time

Time returns the time value embedded in the first 8 bytes of d.

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() bool

Zero reports whether c is all zero.

type NullID

type NullID struct {
	ID    ID
	Valid bool
}

NullID represents an ID that may be null.

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