dilaudid

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2016 License: MIT Imports: 8 Imported by: 0

README


    ~*~ hlian/dilaudid ~*~

    encoding and decoding ULIDs in go

      | everybody is identical in their
      | secret unspoken belief that way
      | deep down they are different
      | from everyone else –DFW

    about

    • this is a fork of imdario/go-ulid

    • we represent ULIDs differently
      (not as bytes)

    • for some reason, ULID libraries
      never include decoding
      • why is that?
      • is it our busy millenial lives?

    • anyway this library decodes

    installation

    $ go get github.com/hlian/dilaudid

    usage

    import "github.com/hlian/dilaudid"
    u := dilaudid.NewRandom()
    v, err := dilaudid.Decode("01B1JK8PG4Y5Z1ED14CACZHRBM")

    json support?

    we have MarshalJSON and UnMarshalJSON defined

    binary subspec support?

    • this does not implement the binary
      part of the specification

    • that part of the specification is
      way too complicated (why split a
      timestamp into an int32 and a
      int16 and then MSB each
      part?)

    performance

    $ go test --bench

    but also, who cares

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ULID

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

A ULID is a 6-byte timestamp (encoded to 10 chars) and a 10-byte nonce (encoded to 16 chars). Those are the facts.

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

func Decode

func Decode(hay string) (ULID, error)

Decode takes a ULID string and returns a ULID containing its constitutent parts (time and nonce)

Returns Nil and an error if the string is malformed or the wrong length

func New

func New(t time.Time, nonce [10]byte) ULID

New returns a ULID with the given time and nonce

Time will be standardized to UTC.

func Unique

func Unique() ULID

Unique returns a unique ULID with the current time

We panic in the unlikely event that we are unable to obtain a nonce number.

func (ULID) MarshalJSON

func (ulid ULID) MarshalJSON() ([]byte, error)

MarshalJSON serializes a ULID as its string representation

func (ULID) String

func (ulid ULID) String() string

String encodes the ULID into a human-friendly string, as per the spec

func (ULID) Time added in v1.1.0

func (ulid ULID) Time() time.Time

Time returns the timestamp in the ULID

func (ULID) UUID added in v1.1.0

func (ulid ULID) UUID() uuid.UUID

UUID uses ULID information to create a UUID

This panics on an invalid UUID. (Which should never happen.)

func (*ULID) UnmarshalJSON

func (ulid *ULID) UnmarshalJSON(bytes []byte) error

UnmarshalJSON deserializes a ULID from its string representation

Time will be standardized to UTC.

Jump to

Keyboard shortcuts

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