sid

package module
v0.0.0-...-660e947 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2019 License: MIT Imports: 6 Imported by: 28

README

sid : generate sortable identifiers

Overview

GoDoc Build Status Code Climate Go Report Card

This package is simple and only provides one function. The aim here is not pure speed, it is for an easy use-case without having to worry about goroutines and locking.

Install

go get github.com/chilts/sid

Example

id1 := sid.Id()
id2 := sid.IdHex()
id3 := sid.IdBase32()
id4 := sid.IdBase64()

fmt.Printf("id1 = %s\n", id1)
fmt.Printf("id2 = %s\n", id2)
fmt.Printf("id3 = %s\n", id3)
fmt.Printf("id4 = %s\n", id4)

// -> "id1 = 1559872035903071353-1186579057231285506"
// -> "id2 = 15a5cf57e7d2a837-6eaafe687e7b3ec3"
// -> "id3 = 1b9efqnl51jj7-4u66ikpfq9ugm"
// -> "id4 = 1IeSBAWW9kK-0cDG64GQgGJ"

Author

By Andrew Chilton, @twitter.

For AppsAttic, @AppsAttic.

License

MIT

(Ends)

Documentation

Overview

Package sid provides the ability to generate Sortable Identifiers. These are also universally unique.

id1 := sid.Id()
id2 := sid.Id()
fmt.Printf("id1 = %s\n", id1)
fmt.Printf("id2 = %s\n", id2)
// -> "id1 = 1IeSBAWW83j-2wgJ4PUtlAr"
// -> "id2 = 1IeSBAWW9kK-0cDG64GQgGJ"

This package is simple and only provides one function. The aim here is not pure speed, it is for an easy use-case without having to worry about goroutines and locking.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Id

func Id() string

Id returns a 39 char string based on timestamp and a random number. The format is "XXXXXXXXXXXXXXXXXXX-YYYYYYYYYYYYYYYYYYY" where X is the timestamp and Y is the random number. If (by any chance) this is called in the same nanosecond, the random number is incremented instead of a new one being generated. This makes sure that two consecutive Ids generated in the same goroutine also ensure those Ids are also sortable.

It is safe to call from different goroutines since it has it's own locking.

func IdBase32

func IdBase32() string

IdBase32 returns a 27 char string based on timestamp and a random number. The format is "XXXXXXXXXXXXX-YYYYYYYYYYYYY" where X is the timestamp and Y is the random number. If (by any chance) this is called in the same nanosecond, the random number is incremented instead of a new one being generated. This makes sure that two consecutive Ids generated in the same goroutine also ensure those Ids are also sortable.

It is safe to call from different goroutines since it has it's own locking.

func IdBase64

func IdBase64() string

IdBase64 returns a 23 char string based on timestamp and a random number. The format is "XXXXXXXXXXX-YYYYYYYYYYY" where X is the timestamp and Y is the random number. If (by any chance) this is called in the same nanosecond, the random number is incremented instead of a new one being generated. This makes sure that two consecutive Ids generated in the same goroutine also ensure those Ids are also sortable.

It is safe to call from different goroutines since it has it's own locking.

func IdHex

func IdHex() string

IdHex returns a char string based on timestamp and a random number. The format is "XXXXXXXXXXXXXXXX-YYYYYYYYYYYYYYYY" where X is the timestamp and Y is the random number. If (by any chance) this is called in the same nanosecond, the random number is incremented instead of a new one being generated. This makes sure that two consecutive Ids generated in the same goroutine also ensure those Ids are also sortable.

It is safe to call from different goroutines since it has it's own locking.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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