Skip to content
Snippets Groups Projects
Commit 3d210f1f authored by Alex Ellis's avatar Alex Ellis
Browse files

Extract handler_set.go


Signed-off-by: default avatarAlex Ellis <alexellis2@gmail.com>
parent 23a71874
No related branches found
No related tags found
No related merge requests found
...@@ -5,40 +5,23 @@ package main ...@@ -5,40 +5,23 @@ package main
import ( import (
"context" "context"
"fmt"
"log" "log"
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
"time" "time"
"fmt"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/gorilla/mux"
internalHandlers "github.com/openfaas/faas/gateway/handlers" internalHandlers "github.com/openfaas/faas/gateway/handlers"
"github.com/openfaas/faas/gateway/metrics" "github.com/openfaas/faas/gateway/metrics"
"github.com/openfaas/faas/gateway/plugin" "github.com/openfaas/faas/gateway/plugin"
"github.com/openfaas/faas/gateway/types" "github.com/openfaas/faas/gateway/types"
natsHandler "github.com/openfaas/nats-queue-worker/handler" 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() { func main() {
logger := logrus.Logger{} logger := logrus.Logger{}
logrus.SetFormatter(&logrus.TextFormatter{}) logrus.SetFormatter(&logrus.TextFormatter{})
...@@ -70,7 +53,8 @@ func main() { ...@@ -70,7 +53,8 @@ func main() {
metricsOptions := metrics.BuildMetricsOptions() metricsOptions := metrics.BuildMetricsOptions()
metrics.RegisterMetrics(metricsOptions) metrics.RegisterMetrics(metricsOptions)
var faasHandlers handlerSet var faasHandlers types.HandlerSet
servicePollInterval := time.Second * 5 servicePollInterval := time.Second * 5
if config.UseExternalProvider() { if config.UseExternalProvider() {
...@@ -93,6 +77,7 @@ func main() { ...@@ -93,6 +77,7 @@ func main() {
// How many times to reschedule a function. // How many times to reschedule a function.
maxRestarts := uint64(5) maxRestarts := uint64(5)
// Delay between container restarts // Delay between container restarts
restartDelay := time.Second * 5 restartDelay := time.Second * 5
...@@ -131,6 +116,7 @@ func main() { ...@@ -131,6 +116,7 @@ func main() {
r.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}/", faasHandlers.Proxy) r.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}/", faasHandlers.Proxy)
r.HandleFunc("/system/alert", faasHandlers.Alert) r.HandleFunc("/system/alert", faasHandlers.Alert)
r.HandleFunc("/system/functions", listFunctions).Methods("GET") r.HandleFunc("/system/functions", listFunctions).Methods("GET")
r.HandleFunc("/system/functions", faasHandlers.DeployFunction).Methods("POST") r.HandleFunc("/system/functions", faasHandlers.DeployFunction).Methods("POST")
r.HandleFunc("/system/functions", faasHandlers.DeleteFunction).Methods("DELETE") r.HandleFunc("/system/functions", faasHandlers.DeleteFunction).Methods("DELETE")
......
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
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment