guid

package
v0.0.0-...-f198d9b Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package guid provides utilities to marshal and unmarshal GUIDs.

This representation of GUID is compatible with golang.org/x/sys/windows and can be used wherever syscall interface/func expects golang.org/x/sys/windows.GUID. Unlike github.com/google/uuid, encoding is always little endian.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GUID

type GUID struct {
	Data1 uint32
	Data2 uint16
	Data3 uint16
	Data4 [8]byte
}

GUID represents a GUID/UUID.

It has the same structure as golang.org/x/sys/windows.GUID so that it can be used with functions expecting that type. It is defined as its own type so that fmt.Stringer, json.Marshaler, json.Unmarshaler, encoding.TextMarshaler and encoding.TextUnmarshaler can be supported. The representation matches that used by native Windows code.

func MustParseGUID

func MustParseGUID[T ~string | ~[]byte](input T) GUID

MustParseGUID parses input as GUID, but upon errors panics.

func NewGUID

func NewGUID() GUID

Generate new [RFC 4122] v4 GUID.

func ParseGUID

func ParseGUID[T ~string | ~[]byte](input T) (GUID, error)

ParseGUID parses a string/byte slice containing a GUID and returns the GUID. The following formats are currently supported are

  • `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`
  • `urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`

func (GUID) AppendString

func (g GUID) AppendString(buf []byte) []byte

AppendString appends hexadecimal encoded string representation of GUID to buf.

func (GUID) IsZero

func (g GUID) IsZero() bool

IsZero returns true if GUID is empty.

func (GUID) MarshalJSON

func (g GUID) MarshalJSON() ([]byte, error)

MarshalText returns the text representation of the GUID.

func (GUID) MarshalText

func (g GUID) MarshalText() ([]byte, error)

MarshalText returns the text representation of the GUID.

func (GUID) String

func (g GUID) String() string

String formats GUID into `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` format.

func (*GUID) UnmarshalJSON

func (g *GUID) UnmarshalJSON(data []byte) error

UnmarshalJSON takes the json representation of a GUID, and unmarshal it into this GUID.

func (*GUID) UnmarshalText

func (g *GUID) UnmarshalText(text []byte) error

UnmarshalText takes the text representation of a GUID, and unmarshal it into this GUID.

Jump to

Keyboard shortcuts

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