mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
server, examples, extensions lint compliant (#1109)
these are all automated changes suggested by golint
This commit is contained in:
26
fnext/api.go
26
fnext/api.go
@@ -6,38 +6,46 @@ import (
|
||||
"github.com/fnproject/fn/api/models"
|
||||
)
|
||||
|
||||
type ApiHandlerFunc func(w http.ResponseWriter, r *http.Request)
|
||||
// APIHandlerFunc is a convenience to make an APIHandler.
|
||||
type APIHandlerFunc func(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
// ServeHTTP calls f(w, r).
|
||||
func (f ApiHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
func (f APIHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
f(w, r)
|
||||
}
|
||||
|
||||
type ApiHandler interface {
|
||||
// APIHandler may be used to add an http endpoint on the versioned route of the Fn API.
|
||||
type APIHandler interface {
|
||||
// Handle(ctx context.Context)
|
||||
ServeHTTP(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
type ApiAppHandler interface {
|
||||
// APIAppHandler may be used to add an http endpoint on the versioned route of fn API,
|
||||
// at /:version/apps/:app
|
||||
type APIAppHandler interface {
|
||||
// Handle(ctx context.Context)
|
||||
ServeHTTP(w http.ResponseWriter, r *http.Request, app *models.App)
|
||||
}
|
||||
|
||||
type ApiAppHandlerFunc func(w http.ResponseWriter, r *http.Request, app *models.App)
|
||||
// APIAppHandlerFunc is a convenience for getting an APIAppHandler.
|
||||
type APIAppHandlerFunc func(w http.ResponseWriter, r *http.Request, app *models.App)
|
||||
|
||||
// ServeHTTP calls f(w, r).
|
||||
func (f ApiAppHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request, app *models.App) {
|
||||
func (f APIAppHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request, app *models.App) {
|
||||
f(w, r, app)
|
||||
}
|
||||
|
||||
type ApiRouteHandler interface {
|
||||
// APIRouteHandler may be used to add an http endpoint on the versioned route of fn API,
|
||||
// at /:version/apps/:app/routes/:route
|
||||
type APIRouteHandler interface {
|
||||
// Handle(ctx context.Context)
|
||||
ServeHTTP(w http.ResponseWriter, r *http.Request, app *models.App, route *models.Route)
|
||||
}
|
||||
|
||||
type ApiRouteHandlerFunc func(w http.ResponseWriter, r *http.Request, app *models.App, route *models.Route)
|
||||
// APIRouteHandlerFunc is a convenience for getting an APIRouteHandler.
|
||||
type APIRouteHandlerFunc func(w http.ResponseWriter, r *http.Request, app *models.App, route *models.Route)
|
||||
|
||||
// ServeHTTP calls f(w, r).
|
||||
func (f ApiRouteHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request, app *models.App, route *models.Route) {
|
||||
func (f APIRouteHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request, app *models.App, route *models.Route) {
|
||||
f(w, r, app, route)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"github.com/fnproject/fn/api/models"
|
||||
)
|
||||
|
||||
// NewDatastore returns a Datastore that wraps the provided Datastore, calling any relevant
|
||||
// listeners around any of the Datastore methods.
|
||||
func NewDatastore(ds models.Datastore, al AppListener, rl RouteListener, fl FnListener, tl TriggerListener) models.Datastore {
|
||||
return &extds{
|
||||
Datastore: ds,
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/fnproject/fn/api/models"
|
||||
)
|
||||
|
||||
// AppListener is an interface used to inject custom code at key points in app lifecycle.
|
||||
// AppListener is an interface used to inject custom code at key points in the app lifecycle.
|
||||
type AppListener interface {
|
||||
// BeforeAppCreate called right before creating App in the database
|
||||
BeforeAppCreate(ctx context.Context, app *models.App) error
|
||||
@@ -41,6 +41,7 @@ type AppListener interface {
|
||||
// }
|
||||
}
|
||||
|
||||
// RouteListener is an interface used to inject custom code at key points in the route lifecycle.
|
||||
type RouteListener interface {
|
||||
// BeforeRouteCreate called before route created in the datastore
|
||||
BeforeRouteCreate(ctx context.Context, route *models.Route) error
|
||||
@@ -88,7 +89,7 @@ type TriggerListener interface {
|
||||
AfterTriggerDelete(ctx context.Context, triggerId string) error
|
||||
}
|
||||
|
||||
// CallListener enables callbacks around Call events
|
||||
// CallListener enables callbacks around Call events.
|
||||
type CallListener interface {
|
||||
// BeforeCall called before a function is executed
|
||||
BeforeCall(ctx context.Context, call *models.Call) error
|
||||
|
||||
@@ -6,14 +6,19 @@ import (
|
||||
"github.com/fnproject/fn/api/models"
|
||||
)
|
||||
|
||||
// Extension is the interface that all extensions must implement in order
|
||||
// to configure themselves against an ExtServer.
|
||||
type Extension interface {
|
||||
Name() string
|
||||
Setup(s ExtServer) error
|
||||
}
|
||||
|
||||
// NOTE: ExtServer limits what the extension should do and prevents dependency loop
|
||||
// ExtServer limits what the extension should do and prevents dependency loop, it can be
|
||||
// used to alter / modify / add the behavior of fn server.
|
||||
type ExtServer interface {
|
||||
// AddAppListener adds a listener that will be invoked around any relevant methods.
|
||||
AddAppListener(listener AppListener)
|
||||
// AddCallListener adds a listener that will be invoked around any call invocations.
|
||||
AddCallListener(listener CallListener)
|
||||
|
||||
// AddAPIMiddleware add middleware
|
||||
@@ -26,15 +31,15 @@ type ExtServer interface {
|
||||
AddRootMiddlewareFunc(m MiddlewareFunc)
|
||||
|
||||
// AddEndpoint adds an endpoint to /v1/x
|
||||
AddEndpoint(method, path string, handler ApiHandler)
|
||||
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(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(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))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user