Browse Source

Update route registration

feature/update-route-registration
Roman Zipp 3 years ago
committed by Fabian Vowie
parent
commit
6be5df8030
No known key found for this signature in database GPG Key ID: C27317C33B27C410
  1. 7
      main.go
  2. 2
      main_test.go

7
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 { for _, pipeline := range pipelines {
r.HandleFunc("/"+pipeline.GetSlug(), func(w http.ResponseWriter, r *http.Request) { r.HandleFunc("/"+pipeline.GetSlug(), func(w http.ResponseWriter, r *http.Request) {
PipelineHandler(pipeline, storageProvider, w, r) PipelineHandler(pipeline, storageProvider, w, r)
@ -64,9 +66,8 @@ func main() {
r := mux.NewRouter() r := mux.NewRouter()
r.Use(authMiddleware.Middleware) r.Use(authMiddleware.Middleware)
r.HandleFunc("/", IndexHandler)
RegisterPipelineRoutes(r, pipes, storageProvider)
RegisterRoutes(r, pipes, storageProvider)
err = http.ListenAndServe(appSettings.Endpoint, r) err = http.ListenAndServe(appSettings.Endpoint, r)
if err != nil { if err != nil {

2
main_test.go

@ -34,7 +34,7 @@ func TestEndpointRoute(t *testing.T) {
router := mux.NewRouter() router := mux.NewRouter()
fs := storage.GetMemoryStorageProvider() fs := storage.GetMemoryStorageProvider()
RegisterPipelineRoutes(router, []pipelines.IPipeline{data}, fs)
RegisterRoutes(router, []pipelines.IPipeline{data}, fs)
request, _ := http.NewRequest("GET", "/"+data.Slug, nil) request, _ := http.NewRequest("GET", "/"+data.Slug, nil)
responseRecorder := httptest.NewRecorder() responseRecorder := httptest.NewRecorder()

Loading…
Cancel
Save