mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
API extensions: Route listerens (#887)
This commit is contained in:
committed by
Reed Allman
parent
7810b3cb9b
commit
6393cf6777
76
api/server/route_listeners.go
Normal file
76
api/server/route_listeners.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/fnproject/fn/api/models"
|
||||
"github.com/fnproject/fn/fnext"
|
||||
)
|
||||
|
||||
type routeListeners []fnext.RouteListener
|
||||
|
||||
var _ fnext.RouteListener = new(routeListeners)
|
||||
|
||||
func (s *Server) AddRouteListener(listener fnext.RouteListener) {
|
||||
*s.routeListeners = append(*s.routeListeners, listener)
|
||||
}
|
||||
|
||||
func (a *routeListeners) BeforeRouteCreate(ctx context.Context, route *models.Route) error {
|
||||
for _, l := range *a {
|
||||
err := l.BeforeRouteCreate(ctx, route)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *routeListeners) AfterRouteCreate(ctx context.Context, route *models.Route) error {
|
||||
for _, l := range *a {
|
||||
err := l.BeforeRouteCreate(ctx, route)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *routeListeners) BeforeRouteUpdate(ctx context.Context, route *models.Route) error {
|
||||
for _, l := range *a {
|
||||
err := l.BeforeRouteUpdate(ctx, route)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *routeListeners) AfterRouteUpdate(ctx context.Context, route *models.Route) error {
|
||||
for _, l := range *a {
|
||||
err := l.AfterRouteUpdate(ctx, route)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *routeListeners) BeforeRouteDelete(ctx context.Context, appName string, routePath string) error {
|
||||
for _, l := range *a {
|
||||
err := l.BeforeRouteDelete(ctx, appName, routePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *routeListeners) AfterRouteDelete(ctx context.Context, appName string, routePath string) error {
|
||||
for _, l := range *a {
|
||||
err := l.AfterRouteDelete(ctx, appName, routePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -111,6 +111,7 @@ type Server struct {
|
||||
certKey string
|
||||
certAuthority string
|
||||
appListeners *appListeners
|
||||
routeListeners *routeListeners
|
||||
rootMiddlewares []fnext.Middleware
|
||||
apiMiddlewares []fnext.Middleware
|
||||
promExporter *prometheus.Exporter
|
||||
@@ -516,7 +517,9 @@ func New(ctx context.Context, opts ...ServerOption) *Server {
|
||||
s.bindHandlers(ctx)
|
||||
|
||||
s.appListeners = new(appListeners)
|
||||
s.datastore = fnext.NewDatastore(s.datastore, s.appListeners)
|
||||
s.routeListeners = new(routeListeners)
|
||||
|
||||
s.datastore = fnext.NewDatastore(s.datastore, s.appListeners, s.routeListeners)
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user