handler

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoopHandler = NewHandler(ContextHandlerFunc(func(ctx context.Context) {}), NextKey)

NoopHandler is a handler that does nothing

Functions

This section is empty.

Types

type Builder

type Builder func(next ...Handler) Handler

Builder is a function that takes a list of "next" Handlers and returns a single Handler.

func (Builder) Handler

func (f Builder) Handler(id Key) Handler

Handler returns the "natural" Handler from the Builder by passing an empty handler to the builder.

type ContextHandler

type ContextHandler interface {
	Handle(context.Context)
}

ContextHandler is the interface for a "chunk" of reconciliation. It either returns, often by adjusting the current key's place in the queue (i.e. via requeue or done) or calls another handler in the chain.

type ContextHandlerFunc

type ContextHandlerFunc func(ctx context.Context)

ContextHandlerFunc is a function type that implements ContextHandler

func (ContextHandlerFunc) Handle

func (f ContextHandlerFunc) Handle(ctx context.Context)

type Handler

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

Handler wraps a ContextHandler and adds a method to create a corresponding Builder. Handler has a Key id so that t can be dereferenced by handlers that branch into multiple options and need to choose a specific one.

func NewHandler

func NewHandler(h ContextHandler, id Key) Handler

NewHandler assigns an id to a ContextHandler implementation and returns a Handler.

func NewHandlerFromFunc

func NewHandlerFromFunc(h ContextHandlerFunc, id Key) Handler

NewHandlerFromFunc creates a new Handler from a ContextHandlerFunc.

func (Handler) Builder

func (h Handler) Builder() Builder

Builder returns the "natural" Builder formed by returning the existing handler.

func (Handler) ID

func (h Handler) ID() Key

ID returns the Key identifier for this handler.

func (Handler) WithID

func (h Handler) WithID(id Key) Handler

WithID returns a copy of this handler with a new ID.

type Handlers

type Handlers []Handler

Handlers adds methods to a list of Handler objects and makes it easy to pick a Handler with a specific ID out of the list.

func (Handlers) Find

func (h Handlers) Find(id Key) (Handler, bool)

Find returns the Handler for the given Key and a boolean that returns true if it was found or false otherwise.

func (Handlers) MustFind

func (h Handlers) MustFind(id Key) Handler

MustFind returns the Handler for the given Key and panics if none is found.

func (Handlers) MustOne

func (h Handlers) MustOne() Handler

MustOne returns a single Handler from the list and panics if the list does not have exactly one Handler.

func (Handlers) ToSet

func (h Handlers) ToSet() map[Key]Handler

ToSet converts the list into a map from Key to Handler. If there are duplicate keys, the later value is picked.

type Key

type Key string

Key is used to identify a given Handler in a set of Handlers

var NextKey Key = "next"

NextKey is a standard key for a list of Handler of length 1

func (Key) Find

func (k Key) Find(handlers Handlers) (Handler, bool)

Find calls Find on the passed in Handlers with the current Key as argument.

func (Key) MustFind

func (k Key) MustFind(handlers Handlers) Handler

MustFind calls MustFind on the passed in Handlers with the current Key as argument.

Jump to

Keyboard shortcuts

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