precondition

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 4 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 moved on, nil otherwise.

func Tag

func Tag(v int64) string

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

Types

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 a version as an entity tag (`"7"`) or bare (`7`). A weak tag, `*` or a list never names one version, so each is refused.

Jump to

Keyboard shortcuts

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