uuidv7

package module
v0.0.0-...-a7e3dca Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: BSD-3-Clause Imports: 10 Imported by: 3

README

uuidv7-go

This package implements a UUIDv7 generator as specified by the New UUID Formats. The first 48 bits contain a big-endian epoch timestamp in milliseconds. This variant provides 74 bytes of entropy.

Examples

Generate UUIDv7 as string
package main

import (
    "fmt"
    "github.com/moroz/uuidv7-go"
)

func main() {
    uuid := uuidv7.Generate()
    fmt.Println(uuid)
}
$ go run .
018e0cd7-986e-7f77-a8b4-8d55de59c992

License

BSD 3-Clause "New" or "Revised" License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorInvalidFormat = errors.New("invalid UUID format")

Functions

This section is empty.

Types

type UUID

type UUID [16]byte
var Nil UUID

func Generate

func Generate() UUID

Generate generates a UUIDv7 with the current timestamp.

func Parse

func Parse(source string) (UUID, error)

func (UUID) Base64

func (u UUID) Base64() string

Base64 returns the UUID encoded as a Base64 string.

func (UUID) Dump

func (u UUID) Dump() string

Dump returns the UUID as a simple hex string, without hyphens.

func (UUID) IsNil

func (u UUID) IsNil() bool

IsNil checks whether an UUID is a nil UUID, i. e. if all bits are set to zero.

func (UUID) MarshalJSON

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

MarshalJSON encodes the UUID as a JSON string. Implements `json.Marshaler` interface.

func (*UUID) Scan

func (u *UUID) Scan(src interface{}) error

Scan implements the `sql.Scanner` interface.

func (UUID) String

func (u UUID) String() string

String returns the UUID in string format, e. g. `"018b1492-8002-7338-bae4-adb32c1b949a"`.

func (*UUID) UnmarshalJSON

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

UnmarshalJSON decodes a UUID from a JSON string.

func (UUID) Value

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

Value implements the `driver.Valuer` interface of `database/sql/driver`. Returns the UUID serialized to string format, e. g. `"018b1492-8002-7338-bae4-adb32c1b949a"`. This is the format expected by PostgreSQL. To get a byte slice, use the slicing operator. The error return value is always nil.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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