hlid

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2025 License: MIT Imports: 9 Imported by: 0

README

HLID: Hexadecimal Lexicographically Sortable Identifier

Features

HLID strikes a good balance between security, efficiency, and usability:

  • 128 bits: fits inside PostgreSQL's UUID type.
  • Thanks to the 48 bit timestamp with 100 microsecond resolution, HLIDs are lexicographically sortable. This makes them efficient for database indexing. The timestamp won't overflow until 2861-12-16.
  • 80 bits of cryptographically secure randomness makes HLIDs usable for secure tokens. You need to generate 155,885,281,596 HLIDs with the same timestamp to have a 1% chance of collision.
  • HLIDs do not contain dashes. This makes HLIDs easier to copy.
  • Hexadecimal encoding makes it possible to use HLIDs in PostgreSQL UUID queries without conversions.

Why not use ...?

Installation

go get github.com/GitRowin/hlid-go

Usage

fmt.Println(hlid.New()) // Example output: 0fca27f9c9315480074ec17d90c3bd52

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ID

type ID [16]byte

func New

func New() ID

func NewWithTime

func NewWithTime(t time.Time) ID

func (ID) MarshalBinary

func (id ID) MarshalBinary() (b []byte, err error)

func (ID) MarshalJSON

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

func (ID) MarshalText

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

func (*ID) Scan

func (id *ID) Scan(value any) error

func (ID) String

func (id ID) String() string

func (*ID) UnmarshalBinary

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

func (*ID) UnmarshalJSON

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

func (*ID) UnmarshalText

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

func (ID) Value

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

Jump to

Keyboard shortcuts

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