feat: add api context and middleware interface
This commit is contained in:
parent
f3127edde1
commit
5730966d35
|
@ -0,0 +1,13 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Context for api handlers
|
||||
type Context struct {
|
||||
context.Context
|
||||
Request *http.Request
|
||||
Response http.ResponseWriter
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package api
|
||||
|
||||
// Middleware for the api for middle ware management (authentication, storing data)
|
||||
type Middleware interface {
|
||||
Handle(ctx *Context) *Context
|
||||
}
|
||||
|
||||
// MiddlewareFunc proxies to a Middleware
|
||||
type MiddlewareFunc func(ctx *Context) *Context
|
||||
|
||||
// Handle implements the Middleware interface
|
||||
func (mwf MiddlewareFunc) Handle(ctx *Context) *Context {
|
||||
return mwf(ctx)
|
||||
}
|
Loading…
Reference in New Issue