feature: add context to handlers and middlewares #17

Closed
xdrm-brackets wants to merge 2 commits from feature/handler-context into 0.3.0
2 changed files with 27 additions and 0 deletions
Showing only changes of commit 5730966d35 - Show all commits

13
api/context.go Normal file
View File

@ -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
}

14
api/middleware.go Normal file
View File

@ -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)
}