Developer Documentation
Go
Updated September 19, 2026

Generate and Work with GUIDs in Go

Generate, parse, format, and validate GUID/UUID values in Go.

A GUID is Microsoft terminology for a 128-bit globally unique identifier. In practice, the canonical textual form is compatible with UUID formatting, although platform APIs may expose additional GUID-specific formats.

Quick Start#

The following example uses the standard Go API or a widely used package for this task.

Quick start#

Go
1// go get github.com/google/uuid2package main34import (5    "fmt"6    "github.com/google/uuid"7)89func main() {10    id := uuid.New()11    fmt.Println(id.String())12}

Common Operations#

This second pattern covers a common production operation or a safer way to handle real input.

Parsing input#

Go
1parsed, err := uuid.Parse(input)2if err != nil {3    return fmt.Errorf("invalid GUID/UUID: %w", err)4}5fmt.Println(parsed.String())

Important Notes#

Keep UUID values in their typed 16-byte representation internally and convert to strings only at serialization boundaries where practical.

Best Practices#

  1. Treat external input as untrusted and handle parse/validation errors explicitly.
  2. Keep encoding, units, formats, and library-specific mapping rules explicit at system boundaries.
  3. Add test vectors that cover empty input, Unicode text, malformed input, and representative production data.

References#

Implement GUID in other languages: