diff --git a/gateway/server.go b/gateway/server.go index 3ec0ed028040f9cca7d9fda0cd9ed2b79a48affe..2e01a1681e2b4cd9bd627ffdb679e0f53a1eaf86 100644 --- a/gateway/server.go +++ b/gateway/server.go @@ -5,40 +5,23 @@ package main import ( "context" + "fmt" "log" "net/http" "net/http/httputil" "time" - "fmt" - "github.com/Sirupsen/logrus" "github.com/docker/docker/client" + "github.com/gorilla/mux" + internalHandlers "github.com/openfaas/faas/gateway/handlers" "github.com/openfaas/faas/gateway/metrics" "github.com/openfaas/faas/gateway/plugin" "github.com/openfaas/faas/gateway/types" natsHandler "github.com/openfaas/nats-queue-worker/handler" - - "github.com/gorilla/mux" ) -type handlerSet struct { - Proxy http.HandlerFunc - DeployFunction http.HandlerFunc - DeleteFunction http.HandlerFunc - ListFunctions http.HandlerFunc - Alert http.HandlerFunc - RoutelessProxy http.HandlerFunc - UpdateFunction http.HandlerFunc - - // QueuedProxy - queue work and return synchronous response - QueuedProxy http.HandlerFunc - - // AsyncReport - report a deferred execution result - AsyncReport http.HandlerFunc -} - func main() { logger := logrus.Logger{} logrus.SetFormatter(&logrus.TextFormatter{}) @@ -70,7 +53,8 @@ func main() { metricsOptions := metrics.BuildMetricsOptions() metrics.RegisterMetrics(metricsOptions) - var faasHandlers handlerSet + var faasHandlers types.HandlerSet + servicePollInterval := time.Second * 5 if config.UseExternalProvider() { @@ -93,6 +77,7 @@ func main() { // How many times to reschedule a function. maxRestarts := uint64(5) + // Delay between container restarts restartDelay := time.Second * 5 @@ -131,6 +116,7 @@ func main() { r.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}/", faasHandlers.Proxy) r.HandleFunc("/system/alert", faasHandlers.Alert) + r.HandleFunc("/system/functions", listFunctions).Methods("GET") r.HandleFunc("/system/functions", faasHandlers.DeployFunction).Methods("POST") r.HandleFunc("/system/functions", faasHandlers.DeleteFunction).Methods("DELETE") diff --git a/gateway/types/handler_set.go b/gateway/types/handler_set.go new file mode 100644 index 0000000000000000000000000000000000000000..79bbd5d43d6f1b69e146259f5019a431d71a669d --- /dev/null +++ b/gateway/types/handler_set.go @@ -0,0 +1,20 @@ +package types + +import "net/http" + +// HandlerSet can be initialized with handlers for binding to mux +type HandlerSet struct { + Proxy http.HandlerFunc + DeployFunction http.HandlerFunc + DeleteFunction http.HandlerFunc + ListFunctions http.HandlerFunc + Alert http.HandlerFunc + RoutelessProxy http.HandlerFunc + UpdateFunction http.HandlerFunc + + // QueuedProxy - queue work and return synchronous response + QueuedProxy http.HandlerFunc + + // AsyncReport - report a deferred execution result + AsyncReport http.HandlerFunc +}