Documentation ¶
Overview ¶
Package midware provides a way to convert a MidwareFunc to an http.HandlerFunc. MidwareFunc is not a literal type but is any func of the form - func(w http.ResponseWriter, r *http.Request, data *struct{...})
Midware is used to inject values into data using reflection.
Index ¶
- Variables
- func GetWR(args []reflect.Value) (w http.ResponseWriter, r *http.Request)
- func NewDecoder(d lhttp.RequestDecoder, fieldName string) linject.Field
- func NewField(fsi linject.FieldInitilizer, fieldName string) linject.Field
- func NewRedirect(fieldName string) linject.Field
- func URL(segment, fieldName string) linject.Field
- type DecoderInitilizer
- type Initilizer
- type Injector
- type Midware
- type Redirect
- type URLFieldSetter
- type WebSocket
Constants ¶
This section is empty.
Variables ¶
var ( HttpHandlerType = filter.NumInEq(3). And(filter.InType(0, httptype.ResponseWriter)). And(filter.InType(1, httptype.Request)) )
var (
Vars = mux.Vars
)
Vars references mux.Vars. It is left exposed for testing.
Functions ¶
func NewDecoder ¶
func NewDecoder(d lhttp.RequestDecoder, fieldName string) linject.Field
NewDecoder creates a magic midware that decodes data from the request and sets it to a field on the magic data type. The field must be a pointer to a struct.
func NewRedirect ¶
NewRedirect creates a Redirect Initilizer. It should be the last Initilizer in the Midware.
Types ¶
type DecoderInitilizer ¶
type DecoderInitilizer struct {
lhttp.RequestDecoder
}
DecoderInitilizer fulfills FieldSetterInitilizer.
func (DecoderInitilizer) InitilizeField ¶
func (di DecoderInitilizer) InitilizeField(ft linject.FuncType, t reflect.Type) linject.FieldInjector
Initilize fulfills FieldSetterInitilizer. It validates that the Type t is a pointer to a struct.
type Initilizer ¶
type Midware ¶
type Midware struct {
linject.Initilizers
}
Midware holds the Initilizers that build the DataInserters for dataType.
func New ¶
func New(initilizers ...linject.Initilizer) *Midware
New creates a set of midware initilizers that can be used to convert midwareFuncs to http.HandlerFuncs.
func (*Midware) Inits ¶
func (m *Midware) Inits(initilizers ...Initilizer) *Midware
type Redirect ¶
type Redirect struct{}
Redirect is solves a side effect of the callbacks. When http.Redirect is invoked it prevents cookies from being written (and possibly other headers). Putting Redirect at the bottom of midware.NewMagic allows redirects to be set and invoked at the end of the call.
func (Redirect) InitilizeField ¶
Initilize fulfills FieldSetterInitilizer.
type URLFieldSetter ¶
type URLFieldSetter struct {
Var string
}
URLFieldSetter references a Var in gorilla/mux.Vars. It fulfills FieldSetterInitilizer and FieldSetter. It is used to extract values from a URL and set them in the magic data field.
type WebSocket ¶
type WebSocket struct { Upgrader websocket.Upgrader ToBuf, FromBuf int lhttp.ErrHandler }
WebSocket can perform two different midware operations. It can attach a *websocket.Conn directly or it can attach a set of []byte channels connected to a websocket.
func (WebSocket) Initilizer ¶
func (ws WebSocket) Initilizer(to, from, conn string) Initilizer
// ChannelInitilizer creates an Initilizer that will abstract the websocket to // a pair of []byte channels.