diff --git a/function/function.go b/function/function.go index 564910d..d37208b 100644 --- a/function/function.go +++ b/function/function.go @@ -25,6 +25,11 @@ type Function struct { Provider *Provider `json:"provider" validate:"required"` } +// Functions is an array of functions. +type Functions struct { + Functions []*Function `json:"functions"` +} + // ID uniquely identifies a function. type ID string diff --git a/httpapi/configapi.go b/httpapi/configapi.go deleted file mode 100644 index 21b37f2..0000000 --- a/httpapi/configapi.go +++ /dev/null @@ -1,63 +0,0 @@ -package httpapi - -import ( - "net/http" - "strconv" - "time" - - "github.com/julienschmidt/httprouter" - "github.com/prometheus/client_golang/prometheus" - "github.com/serverless/event-gateway/function" - "github.com/serverless/event-gateway/subscription" -) - -func init() { - prometheus.MustRegister(requestDuration) -} - -// StartConfigAPI creates a new configuration API server and listens for requests. -func StartConfigAPI(functions function.Service, subscriptions subscription.Service, config ServerConfig) { - router := httprouter.New() - api := &HTTPAPI{ - Functions: functions, - Subscriptions: subscriptions, - } - api.RegisterRoutes(router) - - handler := &http.Server{ - Addr: ":" + strconv.Itoa(int(config.Port)), - Handler: metricsReporter{router}, - ReadTimeout: 3 * time.Second, - WriteTimeout: 3 * time.Second, - } - - server := Server{ - Config: config, - HTTPHandler: handler, - } - - config.ShutdownGuard.Add(1) - go func() { - server.Listen() - config.ShutdownGuard.Done() - }() -} - -var requestDuration = prometheus.NewHistogram( - prometheus.HistogramOpts{ - Namespace: "gateway", - Subsystem: "config", - Name: "request_duration_seconds", - Help: "Bucketed histogram of request duration of config API requests", - Buckets: prometheus.ExponentialBuckets(0.0005, 2, 16), - }) - -type metricsReporter struct { - Handler http.Handler -} - -func (m metricsReporter) ServeHTTP(w http.ResponseWriter, r *http.Request) { - start := time.Now() - m.Handler.ServeHTTP(w, r) - requestDuration.Observe(time.Since(start).Seconds()) -} diff --git a/httpapi/eventsapi.go b/httpapi/eventsapi.go deleted file mode 100644 index 95fb5e9..0000000 --- a/httpapi/eventsapi.go +++ /dev/null @@ -1,28 +0,0 @@ -package httpapi - -import ( - "net/http" - "strconv" - "time" -) - -// StartEventsAPI creates a new gateway endpoint and listens for requests. -func StartEventsAPI(router http.Handler, config ServerConfig) { - handler := &http.Server{ - Addr: ":" + strconv.Itoa(int(config.Port)), - Handler: router, - ReadTimeout: 60 * time.Second, - WriteTimeout: 540 * time.Second, - } - - server := Server{ - Config: config, - HTTPHandler: handler, - } - - config.ShutdownGuard.Add(1) - go func() { - server.Listen() - config.ShutdownGuard.Done() - }() -} diff --git a/httpapi/httpapi.go b/httpapi/httpapi.go index fcda552..5fa0368 100644 --- a/httpapi/httpapi.go +++ b/httpapi/httpapi.go @@ -60,14 +60,10 @@ func (h HTTPAPI) getFunctions(w http.ResponseWriter, r *http.Request, params htt w.WriteHeader(http.StatusInternalServerError) encoder.Encode(&Error{Error: err.Error()}) } else { - encoder.Encode(&functions{fns}) + encoder.Encode(&function.Functions{Functions: fns}) } } -type functions struct { - Functions []*function.Function `json:"functions"` -} - func (h HTTPAPI) registerFunction(w http.ResponseWriter, r *http.Request, params httprouter.Params) { w.Header().Set("Content-Type", "application/json") encoder := json.NewEncoder(w) @@ -211,10 +207,6 @@ func (h HTTPAPI) getSubscriptions(w http.ResponseWriter, r *http.Request, params w.WriteHeader(http.StatusInternalServerError) encoder.Encode(&Error{Error: err.Error()}) } else { - encoder.Encode(&subscriptions{subs}) + encoder.Encode(&subscription.Subscriptions{Subscriptions: subs}) } } - -type subscriptions struct { - Subscriptions []*subscription.Subscription `json:"subscriptions"` -} diff --git a/subscription/subscription.go b/subscription/subscription.go index 94250fb..c4c323b 100644 --- a/subscription/subscription.go +++ b/subscription/subscription.go @@ -15,6 +15,11 @@ type Subscription struct { CORS *CORS `json:"cors,omitempty"` } +// Subscriptions is an array of subscriptions. +type Subscriptions struct { + Subscriptions []*Subscription `json:"subscriptions"` +} + // ID uniquely identifies a subscription. type ID string