diff --git a/api/context.go b/api/context.go new file mode 100644 index 0000000..dab6f17 --- /dev/null +++ b/api/context.go @@ -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 +} diff --git a/api/middleware.go b/api/middleware.go new file mode 100644 index 0000000..3044ff7 --- /dev/null +++ b/api/middleware.go @@ -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) +}