conditional

package
v2.0.0-...-21a9387 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package conditional provides utilities for working with HTTP conditional requests using the `If-Match`, `If-None-Match`, `If-Modified-Since`, and `If-Unmodified-Since` headers along with ETags and last modified times.

In general, conditional requests with tight integration into your data store will be preferred as they are more efficient. However, this package provides a simple way to get started with conditional requests and once the functionality is in place the performance can be improved later. You still get the benefits of not sending extra data over the wire and distributed write protections that prevent different users from overwriting each other's changes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Params

type Params struct {
	IfMatch           []string  `header:"If-Match" doc:"Succeeds if the server's resource matches one of the passed values."`
	IfNoneMatch       []string  `` /* 169-byte string literal not displayed */
	IfModifiedSince   time.Time `header:"If-Modified-Since" doc:"Succeeds if the server's resource date is more recent than the passed date."`
	IfUnmodifiedSince time.Time `header:"If-Unmodified-Since" doc:"Succeeds if the server's resource date is older or the same as the passed date."`
	// contains filtered or unexported fields
}

Params allow clients to send ETags or times to make a read or write conditional based on the state of the resource on the server, e.g. when it was last modified. This is useful for determining when a cache should be updated or to prevent multiple writers from overwriting each other's changes.

func (*Params) HasConditionalParams

func (p *Params) HasConditionalParams() bool

HasConditionalParams returns true if any conditional request headers have been set on the incoming request.

func (*Params) PreconditionFailed

func (p *Params) PreconditionFailed(etag string, modified time.Time) huma.StatusError

PreconditionFailed returns false if no conditional headers are present, or if the values passed fail based on the conditional read/write rules. See also: https://developer.mozilla.org/en-US/docs/Web/HTTP/Conditional_requests. This method assumes there is some fast/efficient way to get a resource's current ETag and/or last-modified time before it is run.

func (*Params) Resolve

func (p *Params) Resolve(ctx huma.Context) []error

Jump to

Keyboard shortcuts

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