Middleware upgrade (#554)

* Adds root level middleware

* Added todo

* Better way for extensions to be added.

* Bad conflict merge?
This commit is contained in:
Travis Reeder
2017-12-05 08:22:03 -08:00
committed by GitHub
parent 9a17c79a3b
commit 0798f9fac8
23 changed files with 660 additions and 287 deletions

40
fnext/setup.go Normal file
View File

@@ -0,0 +1,40 @@
package fnext
import (
"net/http"
"github.com/fnproject/fn/api/models"
)
type Extension interface {
Name() string
Setup(s ExtServer) error
}
// NOTE: ExtServer limits what the extension should do and prevents dependency loop
type ExtServer interface {
AddAppListener(listener AppListener)
AddCallListener(listener CallListener)
// AddAPIMiddleware add middleware
AddAPIMiddleware(m Middleware)
// AddAPIMiddlewareFunc add middlewarefunc
AddAPIMiddlewareFunc(m MiddlewareFunc)
// AddRootMiddleware add middleware add middleware for end user applications
AddRootMiddleware(m Middleware)
// AddRootMiddlewareFunc add middleware for end user applications
AddRootMiddlewareFunc(m MiddlewareFunc)
// AddEndpoint adds an endpoint to /v1/x
AddEndpoint(method, path string, handler ApiHandler)
// AddEndpoint adds an endpoint to /v1/x
AddEndpointFunc(method, path string, handler func(w http.ResponseWriter, r *http.Request))
// AddAppEndpoint adds an endpoints to /v1/apps/:app/x
AddAppEndpoint(method, path string, handler ApiAppHandler)
// AddAppEndpoint adds an endpoints to /v1/apps/:app/x
AddAppEndpointFunc(method, path string, handler func(w http.ResponseWriter, r *http.Request, app *models.App))
// AddRouteEndpoint adds an endpoints to /v1/apps/:app/routes/:route/x
AddRouteEndpoint(method, path string, handler ApiRouteHandler)
// AddRouteEndpoint adds an endpoints to /v1/apps/:app/routes/:route/x
AddRouteEndpointFunc(method, path string, handler func(w http.ResponseWriter, r *http.Request, app *models.App, route *models.Route))
}