dilaudid

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2016 License: MIT Imports: 6 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

    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) 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