locker

package
v0.0.0-...-efe4ef5 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package locker provides an HTTP middleware which allows an HTTPHandler to be locked, returning 423 (locked)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Inject

func Inject(other generichttp.HTTPer, l ManipulableLock)

Inject adds a lock route to a generichttp.HTTPer which is used to manipulate the locker

Types

type AxisLocker

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

AxisLocker is a Locker, but for multi-axis devices, enabling granular locks (per-axis)

func NewAL

func NewAL() *AxisLocker

NewAL returns a new axis locker

func (*AxisLocker) Check

func (al *AxisLocker) Check(next http.Handler) http.Handler

Check is an HTTP middleware that implements the locker

func (*AxisLocker) HTTPGet

func (al *AxisLocker) HTTPGet(w http.ResponseWriter, r *http.Request)

HTTPGet returns Locked() over HTTP as JSON

func (*AxisLocker) HTTPSet

func (al *AxisLocker) HTTPSet(w http.ResponseWriter, r *http.Request)

HTTPSet calls Lock or Unlock based on json:bool on the request body

type Locker

type Locker struct {

	// DoNotProtect is a list of paths not to apply the lock to
	DoNotProtect []string
	// contains filtered or unexported fields
}

Locker is a type which behaves like a sync.Mutex without the blocking, and holds a list of routes (Goji patterns) to not protext

func New

func New() *Locker

New returns a new Locker with DoNotProtect prepopulated with "lock"

func (*Locker) Check

func (l *Locker) Check(next http.Handler) http.Handler

Check is an HTTP middleware that returns http.StatusLocked if Locked() is true, otherwise passes down the line

func (*Locker) HTTPGet

func (l *Locker) HTTPGet(w http.ResponseWriter, r *http.Request)

HTTPGet returns Locked() over HTTP as JSON

func (*Locker) HTTPSet

func (l *Locker) HTTPSet(w http.ResponseWriter, r *http.Request)

HTTPSet calls Lock or Unlock based on json:bool on the request body

func (*Locker) Lock

func (l *Locker) Lock()

Lock the locker

func (*Locker) Locked

func (l *Locker) Locked() bool

Locked returns true if the locker is locked

func (*Locker) Unlock

func (l *Locker) Unlock()

Unlock the locker

type ManipulableLock

type ManipulableLock interface {
	// Check checks if the resource is locked, and is a middleware
	Check(http.Handler) http.Handler

	// Get returns the status of the lock
	HTTPGet(http.ResponseWriter, *http.Request)

	// Set changes the status of the lock
	HTTPSet(http.ResponseWriter, *http.Request)
}

ManipulableLock describes a lock that can be checked and manipulated

Jump to

Keyboard shortcuts

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