pk

package module
v0.0.0-...-6deb74b Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: Apache-2.0 Imports: 12 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Salt

type Salt []byte

type TID

type TID int64

TID is an 63-bit "temporal" ID that is generated from current time and a magic number. 1 million new TIDs can be generated each millisecond, they will run out around year 2262.

func NewTID

func NewTID(now time.Time, n uint) TID

New creates a TID from given time and number, N must be a positive integer under 1 million.

func ParseTID

func ParseTID(s string) (TID, error)

Parse convert string generated by the TIDs String function into a TID.

func (TID) Int64

func (t TID) Int64() int64

Int64 is just a cast from TID to int64.

func (TID) String

func (t TID) String() string

String converts TID to a base-36 string.

func (TID) Time

func (t TID) Time() time.Time

Time converts TID into a unique time.Time with millisecond precision, the micro/nanosecond part is effectively noise.

type TIDSource

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

func NewTIDSource

func NewTIDSource(now time.Time) *TIDSource

func (*TIDSource) Next

func (t *TIDSource) Next(now time.Time) TID

type UID

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

UID is a 120-bit (15 byte) "content ID" for arbitrary binary data, with collision chance of 1 in ~2.66 trillion on trillion unique items.

func NewUID

func NewUID(src ...any) (UID, error)

func ParseUID

func ParseUID(s string) (UID, error)

func ParseUIDBytes

func ParseUIDBytes(b []byte) (UID, error)

func (UID) Bytes

func (u UID) Bytes() []byte

func (UID) Hex

func (u UID) Hex() string

Hex returns a hex encoded presentation of a ID. This should be used when using IDs as filenames on case-insensitive filesystems.

func (UID) MarshalJSON

func (t UID) MarshalJSON() ([]byte, error)

func (UID) String

func (u UID) String() string

func (*UID) UnmarshalJSON

func (u *UID) UnmarshalJSON(data []byte) (err error)

Jump to

Keyboard shortcuts

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