gentleman.v2: gopkg.in/h2non/gentleman.v2/plugin Index | Files

package plugin

import "gopkg.in/h2non/gentleman.v2/plugin"

Package plugin implements a plugin layer for gentleman components. Exports the required interface that must be implemented by plugins.

Plugins are phase-oriented middleware function handlers encapsulated in a simple interface that will be consumed by the middleware layer in order to trigger the plugin handler.

Plugin implementors can decide to build a plugin to handle a unique middleware phase or instead handle multiple phases: request, response, error...

Index

Package Files

plugin.go

type Handlers Uses

type Handlers map[string]context.HandlerFunc

Handlers represents a map to store middleware handler functions per phase.

type Layer Uses

type Layer struct {

    // Handlers defines the required handlers
    Handlers Handlers

    // DefaultHandler is an optional field used to store
    // a default handler for any middleware phase.
    DefaultHandler context.HandlerFunc
    // contains filtered or unexported fields
}

Layer encapsulates an Error, Request and Response function handlers

func New Uses

func New() *Layer

New creates a new plugin layer.

func (*Layer) Disable Uses

func (p *Layer) Disable()

Disable will disable the current plugin

func (*Layer) Disabled Uses

func (p *Layer) Disabled() bool

Disabled returns true if the plugin is enabled

func (*Layer) Enable Uses

func (p *Layer) Enable()

Enable will enable the current plugin

func (*Layer) Exec Uses

func (p *Layer) Exec(phase string, ctx *context.Context, h context.Handler)

Exec executes the plugin handler for the given middleware phase passing the given context.

func (*Layer) Remove Uses

func (p *Layer) Remove()

Remove will remove the plugin from the middleware stack

func (*Layer) Removed Uses

func (p *Layer) Removed() bool

Removed returns true if the plugin Was removed

func (*Layer) SetHandler Uses

func (p *Layer) SetHandler(phase string, handler context.HandlerFunc)

SetHandler uses a new handler function for the given middleware phase.

func (*Layer) SetHandlers Uses

func (p *Layer) SetHandlers(handlers Handlers)

SetHandlers uses a new map of handler functions.

type Plugin Uses

type Plugin interface {
    // Enable enabled the plugin
    Enable()

    // Disable disables the plugin
    Disable()

    // Disabled returns true if the plugin is enabled
    Disabled() bool

    // Remove will remove the plugin from the middleware stack
    Remove()

    // Enabled returns true if the plugin was removed
    Removed() bool

    // Exec executes the plugin handler for a specific middleware phase.
    Exec(string, *context.Context, context.Handler)
}

Plugin interface that must be implemented by plugins

func NewErrorPlugin Uses

func NewErrorPlugin(handler context.HandlerFunc) Plugin

NewErrorPlugin creates a new plugin layer to handle error middleware phase

func NewPhasePlugin Uses

func NewPhasePlugin(phase string, handler context.HandlerFunc) Plugin

NewPhasePlugin creates a new plugin layer to handle a given middleware phase.

func NewRequestPlugin Uses

func NewRequestPlugin(handler context.HandlerFunc) Plugin

NewRequestPlugin creates a new plugin layer to handle request middleware phase

func NewResponsePlugin Uses

func NewResponsePlugin(handler context.HandlerFunc) Plugin

NewResponsePlugin creates a new plugin layer to handle response middleware phase

Package plugin imports 1 packages (graph) and is imported by 64 packages. Updated 2020-02-20. Refresh now. Tools for package owners.