precondition

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package precondition is how a write names the version of the entity it was based on, and how that version is judged against the stored one. Every versioned entity's write requires one, so two people editing the same entity never silently overwrite each other: the second write is refused and its author sees what changed meanwhile.

Index

Constants

This section is empty.

Variables

View Source
var ErrRequired = errors.New("precondition: the write names no version")

ErrRequired is a write that names no version where one is required. It carries no error kind: answering it is a matter of the protocol (HTTP answers 428 precondition_required), so each inbound adapter maps it.

Functions

func Check

func Check(expected Version, current int64) error

Check judges a write based on expected against the entity's current version: ErrRequired without a version, version_mismatch naming the current one when it is not among those named (a weak tag names none), nil otherwise, `*` included.

func Tag

func Tag(v int64) string

Tag returns version v as the strong entity tag an ETag header carries.

Types

type Tags added in v0.7.0

type Tags struct {
	// Any is `*`: it matches whatever the entity's current tag is, as long as
	// the entity exists.
	Any bool
	// Strong are the strong tags the header lists, without their quotes.
	Strong []string
}

Tags is the If-Match header of a request, read as RFC 9110 reads it: `*`, or a list of entity tags. Only strong tags are kept, since a weak one never matches under the strong comparison If-Match uses.

func ParseTags added in v0.7.0

func ParseTags(s string) (Tags, error)

ParseTags reads an If-Match header: `*`, or entity tags separated by commas, each strong (`"7"`, or bare, `7`) or weak (`W/"7"`, which matches nothing). A quoted tag may hold a comma, and empty list elements (`"6", , "7"`) are skipped, as RFC 9110 asks of a list's recipient. A header that is none of these, or lists no tag at all, is refused.

func (Tags) Matches added in v0.7.0

func (t Tags) Matches(current string) bool

Matches reports whether the header holds the entity's current tag.

type Version

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

Version is the version a write was based on, or none when the request named none.

func None

func None() Version

None is the precondition of a write that names no version.

func On

func On(v int64) Version

On is the precondition of a write based on version v.

func Parse

func Parse(s string) (Version, error)

Parse reads the versions a write names in If-Match, as ParseTags does: a version is an entity tag, quoted (`"7"`) or bare (`7`), and `*` and a list are read as RFC 9110 reads them.

Jump to

Keyboard shortcuts

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