Documentation ¶
Index ¶
Constants ¶
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 ¶
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.