decorator

package
v0.0.0-...-de30e9e Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2017 License: BSD-3-Clause Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decorate

func Decorate(h ghttp.Handler, decorators ...Decorator) ghttp.Handler

Decorate decorates the http.Handler with a list of Decorators and returns the decorated http.Handler. Each of the decorators pasted in is a func that takes an http.Hanlder and returns an http.Handler. The idea is to chain the http.Handler h with the decorators so that the decorator funcion is called before h. The Decorators are left associative. The order of the decorators are called as the following (from right / last to the left / first):

h := Decorate(hdl, d3, d2, d1)
//same as
// h:= d1(d2(d3(hdl)))
before d1
before d2
before d3
HandlerFunc
after d3
after d2
after d1

Refer to decorator_test for addtional info.

func DecorateRouter

func DecorateRouter(r ghttp.Router, decorators ...Decorator) ghttp.Router

DecorateRouter decorates each http.Handler in the router with the decorators list and returns the decorated router.

Types

type Decorator

type Decorator func(ghttp.Handler) ghttp.Handler

Decordator is a func that takes an http.Handler and returns an http.Handler. Refer to decorator_test for details of the use cases.

type DecoratorChain

type DecoratorChain []Decorator

DecoratorChain is an array of Decorators.

func Chain

func Chain(decorators ...Decorator) DecoratorChain

Chain chains the Decorators into an array. DecorateChain may be re-used to decorate different http.Handler.

func (DecoratorChain) Append

func (dc DecoratorChain) Append(decorators ...Decorator) DecoratorChain

Append additional Decorators to the given DecoratorChain.

func (DecoratorChain) Decorate

func (dc DecoratorChain) Decorate(h ghttp.Handler) ghttp.Handler

Decorate decortoes an http.Handler with the given DecoratorChain and returns the decorated http Handler.

func (DecoratorChain) DecorateRouter

func (dc DecoratorChain) DecorateRouter(r ghttp.Router) ghttp.Router

DecorateRouter decorates each http.Handler in the router with the given DecoratorChain and returns the decorated router.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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