feat: add api context and middleware interface

This commit is contained in:
Adrien Marquès 2021-04-17 14:03:21 +02:00
parent f3127edde1
commit 5730966d35
2 changed files with 27 additions and 0 deletions

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