xid

package
v0.9.0-beta.6 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NilUUID = UUID{}

NilUUID is a UUID with all bits set to 0. As a string, it is represented as "00000000-0000-0000-0000-000000000000".

View Source
var (
	UUIDURLNamespace = UUIDNamespace{
		Name: "URL",
		UUID: UUID{0x6b, 0xa7, 0xb8, 0x11, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8},
	}
)

Functions

func IsUUIDV1

func IsUUIDV1(value string) bool

IsUUIDV1 returns true if value is UUID v1.

func IsUUIDV4

func IsUUIDV4(value string) bool

IsUUIDV4 returns true if value is UUID v4.

func IsUUIDV5

func IsUUIDV5(value string) bool

IsUUIDV5 returns true if value is UUID v4.

func NanoID

func NanoID() *nanoID

NanoID is implements Nano ID found at https://github.com/ai/nanoid.

To configure the size, use chaining:

id := NanoID().SetSize(12).Get().

To set a different alphabet method chaining:

fmt.Println(NanoID().SetAlphabet("base56").SetSize(13)).

When anything goes wrong generating the Nano ID, the empty string is returned.

func UUIDIsValid

func UUIDIsValid(value string) bool

UUIDIsValid returns whether the string represents a UUID v1, or v4. Note that value is not trimmed of spaces.

Types

type UUID

type UUID [16]byte

UUID defines a type big enough to hold a a RFC 4122 Universally Unique IDentifier.

func UUIDFromString

func UUIDFromString(s string) UUID

UUIDFromString creates a UUID instance from a UUID represented by the string s. If s is not a UUID, the nil UUID (all bits 0) is returned. The string can be with or without hyphens.

func UUIDv4

func UUIDv4() UUID

UUIDv4 returns a UUID version 4 (random). See https://tools.ietf.org/html/rfc4122.

func UUIDv5

func UUIDv5(namespace UUIDNamespace, name string) UUID

UUIDv5 returns a UUID using namespace and name. See https://tools.ietf.org/html/rfc4122.

func (UUID) IsNil

func (u UUID) IsNil() bool

IsNil returns true if all bits are zero.

func (UUID) MarshalJSON

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

MarshalJSON returns the JSON encoding of u.

func (UUID) String

func (u UUID) String() string

CodeAsHex returns the 36 character long string string representation of the UUID. It looks like `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`.

func (*UUID) UnmarshalJSON

func (u *UUID) UnmarshalJSON(data []byte) error

UnmarshalJSON parses the JSON-encoded data and stores the result in u.

func (UUID) Version

func (u UUID) Version() int

Version returns the version number of the UUID as defined by RFC 4122.

type UUIDNamespace

type UUIDNamespace struct {
	Name string
	UUID UUID
}

UUIDNamespace defines a UUID v5 namespace.

Jump to

Keyboard shortcuts

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