b64uuid

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2022 License: MIT Imports: 4 Imported by: 0

README

Go Reference

This package provides B64Uuid type that is essentially renamed Google's UUID aimed to have the UUID's string representation encoded as 22 characters URL-safe Base64 while maintaining identical binary format. For example, these are identical UUIDs:

  • 4686ffb2-0121-4fbf-865f-d9479ab81527
  • Rob_sgEhT7-GX9lHmrgVJw

When parsing strings or unmarshalling into text or JSON, if string length does not equaling 22, B64Uuid will pass the string to the underlying Google's UUID, so both representations of UUID will work correctly.

The more concise Base64URL encoded UUID might be useful when being used in cookies, HTTP REST API etc.

Note that for JSON marshal/unmarshall,

  • Marshalling blank B64UUID will result in JSON null
  • Unmarshalling JSON null would result in blank B64Uuid

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Nil = B64Uuid{}

Empty B64Uuid

Functions

func B64ToUUID

func B64ToUUID(b64 B64Uuid) *guuid.UUID

B64ToUUID converts B64Uuid into Google's UUID

Types

type B64Uuid

type B64Uuid guuid.UUID

func B64FromUuid

func B64FromUuid(gUuid guuid.UUID) B64Uuid

B64FromUuid convert Google's UUID into B64Uuid

func NewRandom

func NewRandom() B64Uuid

Random creates a random B64UUID by calling underlying Google's UUID's NewRandom()

func Parse

func Parse(b64uuidStr string) (u B64Uuid, err error)

Parse tries to parse as Base64Url formatted UUID if the string is 22 characters

When input is not 22 characters, it is passed into underlying Google's UUID type

Empty string immediately results in empty B64Uuid

func (*B64Uuid) IsEmpty

func (u *B64Uuid) IsEmpty() bool

IsEmpty() tests whether the B64Uuid is empty (all zeros)

func (B64Uuid) MarshalBinary

func (u B64Uuid) MarshalBinary() ([]byte, error)

func (B64Uuid) MarshalJSON

func (u B64Uuid) MarshalJSON() ([]byte, error)

func (B64Uuid) MarshalText

func (u B64Uuid) MarshalText() ([]byte, error)

func (*B64Uuid) Scan added in v1.0.6

func (u *B64Uuid) Scan(src interface{}) (err error)

func (B64Uuid) String

func (u B64Uuid) String() string

Convert Outwards

func (*B64Uuid) UnmarshalBinary

func (u *B64Uuid) UnmarshalBinary(inputBytes []byte) error

func (*B64Uuid) UnmarshalJSON

func (u *B64Uuid) UnmarshalJSON(inputJsonBytes []byte) error

func (*B64Uuid) UnmarshalText

func (u *B64Uuid) UnmarshalText(inputJsonBytes []byte) error

Convert Inwards

func (B64Uuid) Value added in v1.0.6

func (u B64Uuid) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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