uuid62

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: Apache-2.0 Imports: 4 Imported by: 2

README

uuid62

GoDoc

Go implementation of short ID generator by using UUIDv1, V4, V6, V7 and base62 inspired by npm uuid62 package.

It always return strings whose length is 21 or 22. It is shorter than string represention of UUID (36). And the results includes only alphabet and numeric characters (no symbols).

package main

import (
	"fmt"
	"github.com/shibukawa/uuid62"
)

func main() {
	// it just returns string
	idString, err := uuid62.V1()
	if err != nil {
		fmt.Println(idString)
	}

	// it also provides API decode/encode between UUID
	uuid, err := Decode(idString)
	if err != nil {
		fmt.Println(idString)
	}
	idStringAgain := Encode(uuid) // idStringAgain == idString
	fmt.Println(idStringAgain)

	ts, err :=
}

API

Generator Functions
  • func uuid62.V1() (string, error)
  • func uuid62.V4() (string, error)
  • func uuid62.V6() (string, error)
  • func uuid62.V7Nano() (string, error)
  • func uuid62.V7Micro() (string, error)
  • func uuid62.V7Milli() (string, error)

They generates UUID string in base62 format.

Helper Functions
  • func uuid62.Decode(uuidString string) (uuid.UUID, error)

Convert string to github.com/gofrs/uuid's UUID object.

  • func uuid62.Encode(uuid.UUID uuidObj) (string, error)

Convert github.com/gofrs/uuid's UUID object to string.

  • func uuid62.Timestamp(uuidString string) (time.Time, error)

Get timestamp from uuid string. It accepts only V1 and V6.

License

Apache 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(uuid62 string) (uuid.UUID, error)

func Encode

func Encode(uuid uuid.UUID) string

func Timestamp added in v1.1.0

func Timestamp(uuid62 string) (time.Time, error)

func V1

func V1() (string, error)

func V4

func V4() (string, error)

func V6 added in v1.1.0

func V6() (string, error)

func V7Micro added in v1.1.0

func V7Micro() (string, error)

func V7Milli added in v1.1.0

func V7Milli() (string, error)

func V7Nano added in v1.1.0

func V7Nano() (string, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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