Skip to content

`uuid` provides asynchronous unique numbering on the server side, based on a draft update of RFC4122.

License

Notifications You must be signed in to change notification settings

WhiteRaven777/uuid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

uuid

GoDoc Widget

uuid provides asynchronous unique numbering on the server side, based on a draft update of RFC4122.

Install

$ go get -u github.com/WhiteRaven777/uuid

Features

  • Generate
    • UUID v1
      • Method to generate UUIDs using time and MAC address
    • UUID v2
      • Method to generate UUIDs using POSIX user ID or group ID to replace part of UUID v1
    • UUID v3
      • Method to generate UUIDs using MD5 in combination with information that is unique in a namespace
    • UUID v4
      • Method to generate UUIDs using random numbers
    • UUID v5
      • Method to generate UUIDs using SHA1 based on UUID v3
    • UUID v6 (draft)
      • Method to generate UUIDs using time based on the Gregorian calendar as well as v1, the clock sequence and random numbers
    • UUID v7 (draft)
      • Method to generate UUIDs using unix time with millisecond or microsecond or nanosecond precision and random numbers
    • UUID v8 (draft)
      • Method to generate UUIDs using any precision and format of time and node when no other method is available
  • Encode
    • Short string
    • UUID format
    • URN format
    • base64 format
  • Decode (parse)
    • Short string
    • UUID format
    • URN format
    • base64 format

Example

See _examples/ for a variety of examples.

package main

import (
	"fmt"
	"time"

	"github.com/WhiteRaven777/uuid"
)

func main() {
	var (
		id  uuid.ID
		uid uuid.UUID
		t time.Time
	)

	id = uuid.New(uuid.UUIDv7)

	// automatically generate based on generation timing
	uid = id.Generate()

	// you can convert it to a string
	fmt.Println("UUID(short)", uid.Short())
	fmt.Println("UUID(default)", uid.String())

	// you can decode (parse) the string into the UUID
	if buf, err := uuid.Parse(uid.String()); err == nil {
		t = id.Decode(buf)
	}
	
	// generate based on any time
	uid = id.Convert(t)

	// you can convert it to a string
	fmt.Println("URN", uid.URN())
	fmt.Println("base64", uid.Base64())
	
	// Note.
	// Regenerated UUIDs from the same time information will almost never have the same value.
	// This is because the time information is combined with random number information.
}

License

Copyright (c) 2021-present WhiteRaven777

Licensed under MIT License

About

`uuid` provides asynchronous unique numbering on the server side, based on a draft update of RFC4122.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages