stayset

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2020 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package stayset helps counting executions and/or instances and getting aware of minimum and maximum parallel instances.

Individual stay-set indicators can be created via New and a namespace. They are automatically registered at a backend for the global retrieval. The indicators got individual identifiers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, r *Registry) context.Context

NewContext creates a context containing a Registry.

Types

type Handler

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

Handler implements the http.Handler.

func NewHandler

func NewHandler(r *Registry) Handler

NewHandler returns an instance of a web handler for the stopwatch.

func (Handler) ServeHTTP

func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the handling function.

type Indication

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

Indication contains one current indication point.

func (*Indication) Stop

func (i *Indication) Stop()

Stop ends the counting.

type IndicatorPoint

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

IndicatorPoint collects the countings of one code section.

func (*IndicatorPoint) Measure

func (ip *IndicatorPoint) Measure(f func())

Measure is a convenience function to measure one anonymous function.

func (*IndicatorPoint) Start

func (ip *IndicatorPoint) Start() Indication

Start begins a new measurement.

func (*IndicatorPoint) Value

func (ip *IndicatorPoint) Value() IndicatorPointValue

Value returns the current value.

type IndicatorPointValue

type IndicatorPointValue struct {
	Namespace string `json:"namespace"`
	ID        string `json:"id"`
	Quantity  int    `json:"quantity"`
	Current   int    `json:"current"`
	Minimum   int    `json:"minimum"`
	Maximum   int    `json:"maximum"`
}

IndicatorPointValue contains the accumulated value of one indicator point.

func (IndicatorPointValue) String

func (ipv IndicatorPointValue) String() string

String implements the fmt.Stringer interface.

type IndicatorPointValues

type IndicatorPointValues []IndicatorPointValue

IndicatorPointValues contains a set of accumulated indicator point values.

type Registry

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

Registry is the register type for a number of SSIs.

func FromContext

func FromContext(ctx context.Context) (*Registry, bool)

FromContext retrieves a Registry from a context.

func New

func New() *Registry

New returns a registry for stay-set indicators.

func (*Registry) ForNamespace

func (r *Registry) ForNamespace(namespace string) *SSI

ForNamespace creates an instance of a SSI with the given namespace. In case that namespace is already in use that SSI will be returned.

func (*Registry) Reset

func (r *Registry) Reset()

Reset clears all namespaces.

func (*Registry) Values

func (r *Registry) Values() IndicatorPointValues

Values returns the values of all metering points.

type SSI

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

SSI allows to measure the execution numbers at multiple counting points in one namespace.

func (*SSI) IndicatorPoint

func (ssi *SSI) IndicatorPoint(id string) *IndicatorPoint

IndicatorPoint returns a new or already existing indicator point with the given ID.

func (*SSI) IndicatorPointWithValue

func (ssi *SSI) IndicatorPointWithValue(id string, value int) *IndicatorPoint

IndicatorPointWithValue returns a new or already existing indicator point with the given ID and and initial value. In case it's already existing the value isn't changed anymore.

func (*SSI) Values

func (ssi *SSI) Values() IndicatorPointValues

Values returns the accumulated counting point values of this SSI.

Jump to

Keyboard shortcuts

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