gate

package
v2.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// Open is the value a gauge is set to that indicates the gate is open
	Open float64 = 1.0

	// Closed is the value a gauge is set to that indicates the gate is closed
	Closed float64 = 0.0
)

Variables

This section is empty.

Functions

func NewConstructor

func NewConstructor(g Interface, options ...ConstructorOption) func(http.Handler) http.Handler

NewConstructor returns an Alice-style constructor which decorates HTTP handlers with gating logic. If supplied, the closed handler is invoked instead of the decorated handler whenever the gate is closed. The closed handler may be nil, in which case a default is used that returns http.StatusServiceUnavailable.

If g is nil, this function panics.

Types

type ConstructorOption

type ConstructorOption func(*constructor)

ConstructorOption configures a gate decorator

func WithClosedHandler

func WithClosedHandler(closed http.Handler) ConstructorOption

WithClosedHandler configures an arbitrary http.Handler that will serve requests when a gate is closed. If the handler is nil, the internal default is used instead.

type GateOption

type GateOption func(*gate)

GateOption is a configuration option for a gate Interface

func WithGauge

func WithGauge(gauge xmetrics.Setter) GateOption

WithGauge configures a gate with a metrics Gauge that tracks the state of the gate.

type Interface

type Interface interface {
	fmt.Stringer

	// Raise opens this gate.  If the gate was raised as a result, this method returns true.  If the
	// gate was already raised, this method returns false.
	Raise() bool

	// Lower closes this gate.  If the gate was lowered as a result, this method returns true.  If the
	// gate was already lowered, this method returns false.
	Lower() bool

	// Open tests if this gate is open
	Open() bool

	// State returns the current state (true for open, false for closed) along with the time
	// at which this gate entered that state.
	State() (bool, time.Time)
}

Interface represents a concurrent condition indicating whether HTTP traffic should be allowed. This type essentially represents an atomic boolean with some extra functionality, such as metrics gathering.

func New

func New(initial bool, options ...GateOption) Interface

New constructs a gate Interface with zero or more options. The returned gate takes on the given initial state, and any configured gauge is updated to reflect this initial state.

type Lever

type Lever struct {
	// Gate is the gate this lever controls
	Gate Interface

	// Parameter is the HTTP parameter, which must be a bool, used to set the state of the gate
	Parameter string
}

Lever is an http.Handler which controls the state of a gate.

func (*Lever) ServeHTTP

func (l *Lever) ServeHTTP(response http.ResponseWriter, request *http.Request)

type Status

type Status struct {
	Gate Interface
}

Status is an http.Handler that reports the status of a gate

func (*Status) ServeHTTP

func (s *Status) ServeHTTP(response http.ResponseWriter, request *http.Request)

Jump to

Keyboard shortcuts

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