Documentation ¶
Overview ¶
Uuid25: 25-digit case-insensitive UUID encoding
Uuid25 is an alternative UUID representation that shortens a UUID string to just 25 digits using the case-insensitive Base36 encoding. This library provides functionality to convert from the conventional UUID formats to Uuid25 and vice versa.
import "github.com/uuid25/go-uuid25" // convert from/to string a, _ := uuid25.Parse("8da942a4-1fbe-4ca6-852c-95c473229c7d") assert(a.String() == "8dx554y5rzerz1syhqsvsdw8t") assert(a.ToHyphenated() == "8da942a4-1fbe-4ca6-852c-95c473229c7d") // convert from/to 128-bit byte array b := uuid25.FromBytes([]byte{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}) assert(b.String() == "f5lxx1zz5pnorynqglhzmsp33") for _, x := range b.ToBytes() { assert(x == 0xff) } // convert from/to other popular textual representations c := make([]uuid25.Uuid25, 4) c[0], _ = uuid25.Parse("e7a1d63b711744238988afcf12161878") c[1], _ = uuid25.Parse("e7a1d63b-7117-4423-8988-afcf12161878") c[2], _ = uuid25.Parse("{e7a1d63b-7117-4423-8988-afcf12161878}") c[3], _ = uuid25.Parse("urn:uuid:e7a1d63b-7117-4423-8988-afcf12161878") for _, x := range c { assert(x.String() == "dpoadk8izg9y4tte7vy1xt94o") } d, _ := uuid25.Parse("dpoadk8izg9y4tte7vy1xt94o") assert(d.ToHex() == "e7a1d63b711744238988afcf12161878") assert(d.ToHyphenated() == "e7a1d63b-7117-4423-8988-afcf12161878") assert(d.ToBraced() == "{e7a1d63b-7117-4423-8988-afcf12161878}") assert(d.ToUrn() == "urn:uuid:e7a1d63b-7117-4423-8988-afcf12161878") func assert(c bool) { if !c { panic("assertion failed") } }
Index ¶
- type Uuid25
- func FromBytes(uuidBytes []byte) Uuid25
- func Parse(uuidString string) (Uuid25, error)
- func ParseBraced(uuidString string) (Uuid25, error)
- func ParseHex(uuidString string) (Uuid25, error)
- func ParseHyphenated(uuidString string) (Uuid25, error)
- func ParseUrn(uuidString string) (Uuid25, error)
- func ParseUuid25(uuidString string) (Uuid25, error)
- func (uuid25 Uuid25) MarshalBinary() (data []byte, err error)
- func (uuid25 Uuid25) MarshalText() (text []byte, err error)
- func (uuid25 *Uuid25) Scan(src any) error
- func (uuid25 Uuid25) String() string
- func (uuid25 Uuid25) ToBraced() string
- func (uuid25 Uuid25) ToBytes() [16]byte
- func (uuid25 Uuid25) ToHex() string
- func (uuid25 Uuid25) ToHyphenated() string
- func (uuid25 Uuid25) ToUrn() string
- func (uuid25 *Uuid25) UnmarshalBinary(data []byte) error
- func (uuid25 *Uuid25) UnmarshalText(text []byte) error
- func (uuid25 Uuid25) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Uuid25 ¶
type Uuid25 string
Primary value type containing the Uuid25 representation of a UUID.
A valid value of this type must be constructed through FromBytes() or one of Parse*() functions.
func Parse ¶
Creates an instance from a UUID string representation.
This method accepts the following formats:
- 25-digit Base36 Uuid25 format: `3ud3gtvgolimgu9lah6aie99o`
- 32-digit hexadecimal format without hyphens: `40eb9860cf3e45e2a90eb82236ac806c`
- 8-4-4-4-12 hyphenated format: `40eb9860-cf3e-45e2-a90e-b82236ac806c`
- Hyphenated format with surrounding braces: `{40eb9860-cf3e-45e2-a90e-b82236ac806c}`
- RFC 4122 URN format: `urn:uuid:40eb9860-cf3e-45e2-a90e-b82236ac806c`
func ParseBraced ¶
Creates an instance from the hyphenated format with surrounding braces: `{40eb9860-cf3e-45e2-a90e-b82236ac806c}`.
func ParseHex ¶
Creates an instance from the 32-digit hexadecimal format without hyphens: `40eb9860cf3e45e2a90eb82236ac806c`.
func ParseHyphenated ¶
Creates an instance from the 8-4-4-4-12 hyphenated format: `40eb9860-cf3e-45e2-a90e-b82236ac806c`.
func ParseUrn ¶
Creates an instance from the RFC 4122 URN format: `urn:uuid:40eb9860-cf3e-45e2-a90e-b82236ac806c`.
func ParseUuid25 ¶
Creates an instance from the 25-digit Base36 Uuid25 format: `3ud3gtvgolimgu9lah6aie99o`.
func (Uuid25) MarshalBinary ¶
Implements the encoding.BinaryMarshaler interface.
func (Uuid25) MarshalText ¶
Implements the encoding.TextMarshaler interface.
func (Uuid25) ToBraced ¶
Formats this type in the hyphenated format with surrounding braces: `{40eb9860-cf3e-45e2-a90e-b82236ac806c}`.
func (Uuid25) ToHex ¶
Formats this type in the 32-digit hexadecimal format without hyphens: `40eb9860cf3e45e2a90eb82236ac806c`.
func (Uuid25) ToHyphenated ¶
Formats this type in the 8-4-4-4-12 hyphenated format: `40eb9860-cf3e-45e2-a90e-b82236ac806c`.
func (Uuid25) ToUrn ¶
Formats this type in the RFC 4122 URN format: `urn:uuid:40eb9860-cf3e-45e2-a90e-b82236ac806c`.
func (*Uuid25) UnmarshalBinary ¶
Implements the encoding.BinaryUnmarshaler interface.
func (*Uuid25) UnmarshalText ¶
Implements the encoding.TextUnmarshaler interface.