Documentation ¶
Overview ¶
Package id generates unique random identifiers.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New() string
New returns a new random string consisting of a legible character set. It is not suitable for cryptographic uses.
Example ¶
package main import ( "fmt" "github.com/komuw/ong/id" ) func main() { fmt.Println(id.New()) }
Output:
func Random ¶
Random generates a random string of size n consisting of a legible character set. If n < 1 or significantly large, it is set to reasonable bounds. It is not suitable for cryptographic uses.
Example ¶
package main import ( "fmt" "github.com/komuw/ong/id" ) func main() { size := 34 s := id.Random(size) if len(s) != size { panic("mismatched sizes") } fmt.Println(s) }
Output:
Types ¶
type UUID ¶ added in v0.0.56
type UUID [16]byte
UUID represents a universally unique identifier. Also see UUID4 and UUID8
func UUID4 ¶ added in v0.0.56
func UUID4() UUID
UUID4 generates a version 4 UUID. It is not correlated with timestamp, thus, when used as the identifief of an object, it does not leak its creation time. On the other hand, this means that it has poor database index locality unlike UUID8. It might also be a good use as a shard key.
It panics on error.
func UUID8 ¶ added in v0.0.56
func UUID8() UUID
UUID8 generates a version 8 UUID. Version 8 provides an RFC-compatible format for experimental/specific use cases.
This one is mostly like version 7 except it uses nanosecond precision instead of millisecond. It is correlated with timestamp, thus, when used as the identifief of an object, it has good database locality. On the other hand, this means that it can leak the object's creation time unlike UUID4.
It panics on error.
func (UUID) String ¶ added in v0.0.56
String implements fmt.Stringer for uuid.