-
Notifications
You must be signed in to change notification settings - Fork 8
/
middleware.go
29 lines (24 loc) · 987 Bytes
/
middleware.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package yarf
// MiddlewareHandler interface provides the methods for request filters
// that needs to run before, or after, every request Resource is executed.
type MiddlewareHandler interface {
PreDispatch(*Context) error
PostDispatch(*Context) error
End(*Context) error
}
// Middleware struct is the default implementation of a Middleware and does nothing.
// Users can either implement both methods or composite this struct into their own.
// Both methods needs to be present to satisfy the MiddlewareHandler interface.
type Middleware struct{}
// PreDispatch includes code to be executed before every Resource request.
func (m *Middleware) PreDispatch(c *Context) error {
return nil
}
// PostDispatch includes code to be executed after every Resource request.
func (m *Middleware) PostDispatch(c *Context) error {
return nil
}
// End will be executed ALWAYS after every request, even if there were errors present.
func (m *Middleware) End(c *Context) error {
return nil
}