guid

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: BSD-2-Clause Imports: 3 Imported by: 85

README

GoDoc

guid

The guid package implements a 16-byte guid/uuid type. It supports parsing of guid strings, validation of guids, and random generation of guids according to RFC-4122.

See http://godoc.org/github.com/beevik/guid for the godoc-formatted API documentation.

Example: Parsing a guid
g, err := guid.ParseString("67a23ff3-20be-4420-9274-d16f2833d595")
Example: Generating a random guid
g := guid.New()
Example: Validating a guid string
s0 := "67a23ff3-20be-4420-9274-d16f2833d595"
s1 := "67a23ff3-20be-4420-9274"
fmt.Println("s0 a guid?  ", guid.IsGuid(s0))
fmt.Println("s0 a guid?  ", guid.IsGuid(s1))

Output:

s0 a guid?  true
s1 a guid?  false
Example: Converting a guid to a string
for i := 0; i < 4; i++ {
	g := guid.New()
	fmt.Println("guid: %s  GUID: %s\n", g.String(), g.StringUpper())
}

Output:

guid: 9a5bb29c-cdcd-4b1b-a039-b88d1271ab4c  GUID: 9A5BB29C-CDCD-4B1B-A039-B88D1271AB4C
guid: efeeee74-aea6-4fa9-8037-8d3a3f883d3f  GUID: EFEEEE74-AEA6-4FA9-8037-8D3A3F883D3F
guid: 773730b7-7b5d-4ef0-80ed-f52617d5b688  GUID: 773730B7-7B5D-4EF0-80ED-F52617D5B688
guid: 256f523f-e65e-4451-9381-1d561abbc645  GUID: 256F523F-E65E-4451-9381-1D561ABBC645

Documentation

Overview

Package guid defines a type for globally unique identifiers. It provides functions to generate RFC 4122-compliant guids, to parse strings into guids, and to convert guids to strings.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("guid: invalid format")

ErrInvalid is returned when parsing a string that is not formatted as a valid guid.

Functions

func IsGuid

func IsGuid(s string) bool

IsGuid returns true if the string contains a properly formatted Guid.

func NewString

func NewString() string

NewString is a helper function that returns a random RFC 4122-comformant version 4 Guid as a string.

Types

type Guid

type Guid [16]byte

Guid is a globally unique 16 byte identifier

func New

func New() *Guid

New generates a random RFC 4122-conformant version 4 Guid.

func ParseString

func ParseString(s string) (*Guid, error)

ParseString returns the Guid represented by the string s.

Example

Parse a string containing a guid.

package main

import (
	"fmt"

	"github.com/beevik/guid"
)

func main() {
	g, err := guid.ParseString("0e545c9c-f942-4988-4ab0-145274cfaded")
	if err != nil {
		fmt.Printf("Guid: %v\n", g)
	}
}
Output:

func (*Guid) IsConformant

func (g *Guid) IsConformant() bool

IsConformant determines if the Guid is RFC 4122-conformant. If the variant is "reserved for future definition" or the version is unknown, then it is non-conformant.

func (*Guid) String

func (g *Guid) String() string

String returns a standard hexadecimal string version of the Guid. Lowercase characters are used.

func (*Guid) StringUpper

func (g *Guid) StringUpper() string

StringUpper returns a standard hexadecimal string version of the Guid. Uppercase characters are used.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳