From 6be5df80301aa3a88766eb31e2d35222119aad5b Mon Sep 17 00:00:00 2001 From: Roman Zipp Date: Sun, 23 Jan 2022 17:10:26 +0100 Subject: [PATCH] Update route registration --- main.go | 7 ++++--- main_test.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 33cf1f7..16ed52a 100644 --- a/main.go +++ b/main.go @@ -36,7 +36,9 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) { } } -func RegisterPipelineRoutes(r *mux.Router, pipelines []pipelines.IPipeline, storageProvider storage.IStorageProvider) { +func RegisterRoutes(r *mux.Router, pipelines []pipelines.IPipeline, storageProvider storage.IStorageProvider) { + r.HandleFunc("/", IndexHandler) + for _, pipeline := range pipelines { r.HandleFunc("/"+pipeline.GetSlug(), func(w http.ResponseWriter, r *http.Request) { PipelineHandler(pipeline, storageProvider, w, r) @@ -64,9 +66,8 @@ func main() { r := mux.NewRouter() r.Use(authMiddleware.Middleware) - r.HandleFunc("/", IndexHandler) - RegisterPipelineRoutes(r, pipes, storageProvider) + RegisterRoutes(r, pipes, storageProvider) err = http.ListenAndServe(appSettings.Endpoint, r) if err != nil { diff --git a/main_test.go b/main_test.go index 0e2941d..cd2b0c1 100644 --- a/main_test.go +++ b/main_test.go @@ -34,7 +34,7 @@ func TestEndpointRoute(t *testing.T) { router := mux.NewRouter() fs := storage.GetMemoryStorageProvider() - RegisterPipelineRoutes(router, []pipelines.IPipeline{data}, fs) + RegisterRoutes(router, []pipelines.IPipeline{data}, fs) request, _ := http.NewRequest("GET", "/"+data.Slug, nil) responseRecorder := httptest.NewRecorder()