package module
v2.0.5+incompatible Latest Latest

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

Go to latest
Published: Oct 20, 2018 License: MIT Imports: 1 Imported by: 157


UUID package for Go language

Build Status Coverage Status GoDoc

NOTE: This is a fork of https://github.com/satori/go.uuid. Due to this issue we were forced to fork. :(

THIS PACKAGE IS DEPRECATED: please use github.com/gofrs/uuid instead.


This package provides pure Go implementation of Universally Unique Identifier (UUID). Supported both creation and parsing of UUIDs.

With 100% test coverage and benchmarks out of box.

Supported versions:

  • Version 1, based on timestamp and MAC address (RFC 4122)
  • Version 2, based on timestamp, MAC address and POSIX UID/GID (DCE 1.1)
  • Version 3, based on MD5 hashing (RFC 4122)
  • Version 4, based on random numbers (RFC 4122)
  • Version 5, based on SHA-1 hashing (RFC 4122)


Use the go command:

$ go get github.com/gobuffalo/uuid


UUID package requires Go >= 1.2.


package main

import (

func main() {
	// Creating UUID Version 4
	// panic on error
	u1 := uuid.Must(uuid.NewV4())
	fmt.Printf("UUIDv4: %s\n", u1)

	// or error handling
	u2, err := uuid.NewV4()
	if err != nil {
		fmt.Printf("Something went wrong: %s", err)
	fmt.Printf("UUIDv4: %s\n", u2)

	// Parsing UUID from string input
	u2, err := uuid.FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
	if err != nil {
		fmt.Printf("Something went wrong: %s", err)
	fmt.Printf("Successfully parsed: %s", u2)


Documentation is hosted at GoDoc project.

Copyright (C) 2013-2018 by Maxim Bublis b@codemonkey.ru.

UUID package released under MIT License. See LICENSE for details.



Package uuid provides implementation of Universally Unique Identifier (UUID). Supported versions are 1, 3, 4 and 5 (as specified in RFC 4122) and version 2 (as specified in DCE 1.1).



View Source
const (
	V1 = guuid.V1
	V2 = guuid.V2
	V3 = guuid.V3
	V4 = guuid.V4
	V5 = guuid.V5

UUID versions

View Source
const (
	VariantNCS       = guuid.VariantNCS
	VariantRFC4122   = guuid.VariantRFC4122
	VariantMicrosoft = guuid.VariantMicrosoft
	VariantFuture    = guuid.VariantFuture

UUID layout variants.

View Source
const (
	DomainPerson = guuid.DomainPerson
	DomainGroup  = guuid.DomainGroup
	DomainOrg    = guuid.DomainOrg

UUID DCE domains.

View Source
const Size = guuid.Size

Size of a UUID in bytes.


View Source
var (
	NamespaceDNS  = guuid.NamespaceDNS
	NamespaceURL  = guuid.NamespaceURL
	NamespaceOID  = guuid.NamespaceOID
	NamespaceX500 = guuid.NamespaceX500

Predefined namespace UUIDs.

View Source
var FromBytes = guuid.FromBytes

FromBytes returns UUID converted from raw byte slice input. It will return error if the slice isn't 16 bytes long.

View Source
var FromBytesOrNil = guuid.FromBytesOrNil

FromBytesOrNil returns UUID converted from raw byte slice input. Same behavior as FromBytes, but returns a Nil UUID on error.

View Source
var FromString = guuid.FromString

FromString returns UUID parsed from string input. Input is expected in a form accepted by UnmarshalText.

View Source
var FromStringOrNil = guuid.FromStringOrNil

FromStringOrNil returns UUID parsed from string input. Same behavior as FromString, but returns a Nil UUID on error.

View Source
var NewV1 = guuid.NewV1

NewV1 returns UUID based on current timestamp and MAC address.

View Source
var NewV2 = guuid.NewV2

NewV2 returns DCE Security UUID based on POSIX UID/GID.

View Source
var NewV3 = guuid.NewV3

NewV3 returns UUID based on MD5 hash of namespace UUID and name.

View Source
var NewV4 = guuid.NewV4

NewV4 returns random generated UUID.

View Source
var NewV5 = guuid.NewV5

NewV5 returns UUID based on SHA-1 hash of namespace UUID and name.

View Source
var Nil = guuid.Nil

Nil is special form of UUID that is specified to have all 128 bits set to zero.


This section is empty.


type Generator added in v1.2.0

type Generator = guuid.Generator

Generator provides interface for generating UUIDs.

type NullUUID added in v1.1.0

type NullUUID = guuid.NullUUID

NullUUID can be used with the standard sql package to represent a UUID value that can be NULL in the database

type UUID

type UUID = guuid.UUID

UUID representation compliant with specification described in RFC 4122.

func Must added in v1.2.0

func Must(u UUID, err error) UUID

Must is a helper that wraps a call to a function returning (UUID, error) and panics if the error is non-nil. It is intended for use in variable initializations such as

var packageUUID = uuid.Must(uuid.FromString("123e4567-e89b-12d3-a456-426655440000"));

Jump to

Keyboard shortcuts

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