trid

package module
v0.0.0-...-d2dfa00 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2020 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

trid

GoDoc

Totally Random Identifiers

trid is a GUID library built for speed, size, and anonymity.

Cryptographically secure random GUIDs can be generated at extremely high speeds and very low memory usage:

BenchmarkNew-4                   6769496               174 ns/op              16 B/op          1 allocs/op
BenchmarkToString-4             33261237                36.9 ns/op            32 B/op          1 allocs/op
BenchmarkFromBytes-4            478937239                2.48 ns/op            0 B/op          0 allocs/op
BenchmarkFromString-4           44093491                26.2 ns/op             0 B/op          0 allocs/op

GUIDs are 12 bytes in length raw, and 20 characters in length encoded as strings. Base32 encoding is used so that the non alphanumeric characters of base64 don't cause a problem.

trid was heavily inspired by xid, much of the code is taken from there. This repository was necessary for me as I do not want PIDs, timestamps, or machine identifiers in my GUIDs, and I don't care if my GUIDs are sortable.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidID is returned when trying to unmarshal an invalid ID
	ErrInvalidID = errors.New("trid: invalid ID")
)

Functions

This section is empty.

Types

type ID

type ID [rawLen]byte

ID represents a unique request id

func FromBytes

func FromBytes(b []byte) (ID, error)

FromBytes convert the byte array representation of `ID` back to `ID`

func FromString

func FromString(id string) (ID, error)

FromString reads an ID from its string representation

func New

func New() ID

New generates a globally unique ID

func NilID

func NilID() ID

NilID returns a zero value for `trid.ID`.

func (ID) Bytes

func (id ID) Bytes() []byte

Bytes returns the byte array representation of `ID`

func (ID) IsNil

func (id ID) IsNil() bool

IsNil Returns true if this is a "nil" ID

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

MarshalJSON implements encoding/json Marshaler interface

func (ID) MarshalText

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

MarshalText implements encoding/text TextMarshaler interface

func (ID) String

func (id ID) String() string

String returns a base32 hex lowercased with no padding representation of the id (char set is 0-9, a-v).

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(b []byte) error

UnmarshalJSON implements encoding/json Unmarshaler interface

func (*ID) UnmarshalText

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

UnmarshalText implements encoding/text TextUnmarshaler interface

Jump to

Keyboard shortcuts

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