ulid

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

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

Go to latest
Published: Jan 16, 2018 License: MIT Imports: 3 Imported by: 4

README

Universally Unique Lexicographically Sortable Identifier

Project status Go Report Card GoDoc MIT licensed

alizain/ulid port to Golang (binary format implemented).

Why ULID?

Check out ULID's README.

About this implementation

Important: this repository has been archived. Please use oklog/ulid implementation.

I ported it to see how fast would be the same algorithm in Go. Also, it is cryptographically secure using crypto/rand.

Installation
go get github.com/imdario/go-ulid
Usage
import (
    "github.com/imdario/go-ulid"
)

// ...

u := ulid.New()
Performance

On a Intel Core 2 Duo 6600 @ 2.40 GHz, Windows 10 and Go 1.6.3:

BenchmarkULID-2                  1000000              1029 ns/op              16 B/op          1 allocs/op
BenchmarkEncodedULID-2           1000000              1249 ns/op              48 B/op          2 allocs/op
BenchmarkSingleEncodedULID-2    10000000               206 ns/op              32 B/op          1 allocs/op

Approx. 800.640 op/s, 46 times faster than Javascript original implementation.

How does it compare to UUID?

Using google/uuid:

BenchmarkUUID-2                  1000000              1041 ns/op              16 B/op          1 allocs/op
BenchmarkEncodedUUID-2           1000000              1407 ns/op              64 B/op          2 allocs/op
BenchmarkSingleEncodedUUID-2     5000000               302 ns/op              48 B/op          1 allocs/op

go-ulid is about 12% faster than Google's UUID!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ULID

type ULID [16]byte

A ULID is a 16 byte Universally Unique Lexicographically Sortable Identifier

var (

	// Nil as empty value to handle errors
	Nil ULID
)

func Must

func Must(ulid ULID, err error) ULID

Must returns ulid if err is nil and panics otherwise.

func New

func New() ULID

New is creates a new random ULID or panics. New is equivalent to the expression

ulid.Must(ulid.NewRandom())

func NewRandom

func NewRandom() (ULID, error)

NewRandom returns a ULID (binary implementation) or panics.

The strength of the ULIDs is based on the strength of the crypto/rand package.

func (ULID) String

func (ulid ULID) String() string

String returns the string form of ulid (26 characters, non-standard base 32)

Jump to

Keyboard shortcuts

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