etag

package
v0.0.0-...-1db7b98 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package etag provides functions for parsing and generating globally unique ETags from a UUID and updated-at timestamp.

Tags generated by this package are designed to support optimistic concurrency control at the web server and database levels without requiring a full hash of the resource or any additional data to be persisted.

For Postgres, the resolution of the timestamp field is 1 microsecond, which is sufficient for all expected workloads.

All tags generated by this package are considered strong ETags, since identical tags necessarily correspond to identical resources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ETag

type ETag struct {
	// contains filtered or unexported fields
}

ETag uniquely identifies a version of an entity.

func New

func New(id uuid.UUID, updatedAt time.Time) ETag

func Parse

func Parse(raw string) (ETag, error)

Parse parses an ETag from a string.

func Random

func Random() ETag

Random returns an ETag with a random ID and a timestamp within the last year.

func (ETag) ID

func (e ETag) ID() uuid.UUID

func (ETag) String

func (e ETag) String() string

func (ETag) UpdatedAt

func (e ETag) UpdatedAt() time.Time

type ParseETagError

type ParseETagError struct {
	RawETag string
	Cause   error
}

ParseETagError represents any failure to parse an ETag from a string.

func (*ParseETagError) Error

func (e *ParseETagError) Error() string

Jump to

Keyboard shortcuts

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