From bda99464f1452fc225822c2c031d8d5ccc254afc Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Fri, 7 Nov 2025 23:12:36 +0100 Subject: [PATCH] fix path parameter handling in REST api (#563) --- internal/app/api/v1/handlers/endpoint_interface.go | 6 +++--- internal/app/api/v1/handlers/endpoint_metrics.go | 6 +++--- internal/app/api/v1/handlers/endpoint_peer.go | 12 ++++++------ internal/app/api/v1/handlers/endpoint_user.go | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/internal/app/api/v1/handlers/endpoint_interface.go b/internal/app/api/v1/handlers/endpoint_interface.go index 1ea7241..f87fa3b 100644 --- a/internal/app/api/v1/handlers/endpoint_interface.go +++ b/internal/app/api/v1/handlers/endpoint_interface.go @@ -48,12 +48,12 @@ func (e InterfaceEndpoint) RegisterRoutes(g *routegroup.Bundle) { apiGroup.Use(e.authenticator.LoggedIn(ScopeAdmin)) apiGroup.HandleFunc("GET /all", e.handleAllGet()) - apiGroup.HandleFunc("GET /by-id/{id}", e.handleByIdGet()) + apiGroup.HandleFunc("GET /by-id/{id...}", e.handleByIdGet()) apiGroup.HandleFunc("GET /prepare", e.handlePrepareGet()) apiGroup.HandleFunc("POST /new", e.handleCreatePost()) - apiGroup.HandleFunc("PUT /by-id/{id}", e.handleUpdatePut()) - apiGroup.HandleFunc("DELETE /by-id/{id}", e.handleDelete()) + apiGroup.HandleFunc("PUT /by-id/{id...}", e.handleUpdatePut()) + apiGroup.HandleFunc("DELETE /by-id/{id...}", e.handleDelete()) } // handleAllGet returns a gorm Handler function. diff --git a/internal/app/api/v1/handlers/endpoint_metrics.go b/internal/app/api/v1/handlers/endpoint_metrics.go index 5629d99..737c489 100644 --- a/internal/app/api/v1/handlers/endpoint_metrics.go +++ b/internal/app/api/v1/handlers/endpoint_metrics.go @@ -44,10 +44,10 @@ func (e MetricsEndpoint) RegisterRoutes(g *routegroup.Bundle) { apiGroup := g.Mount("/metrics") apiGroup.Use(e.authenticator.LoggedIn()) - apiGroup.With(e.authenticator.LoggedIn(ScopeAdmin)).HandleFunc("GET /by-interface/{id}", + apiGroup.With(e.authenticator.LoggedIn(ScopeAdmin)).HandleFunc("GET /by-interface/{id...}", e.handleMetricsForInterfaceGet()) - apiGroup.HandleFunc("GET /by-user/{id}", e.handleMetricsForUserGet()) - apiGroup.HandleFunc("GET /by-peer/{id}", e.handleMetricsForPeerGet()) + apiGroup.HandleFunc("GET /by-user/{id...}", e.handleMetricsForUserGet()) + apiGroup.HandleFunc("GET /by-peer/{id...}", e.handleMetricsForPeerGet()) } // handleMetricsForInterfaceGet returns a gorm Handler function. diff --git a/internal/app/api/v1/handlers/endpoint_peer.go b/internal/app/api/v1/handlers/endpoint_peer.go index 393143e..c1999f6 100644 --- a/internal/app/api/v1/handlers/endpoint_peer.go +++ b/internal/app/api/v1/handlers/endpoint_peer.go @@ -47,15 +47,15 @@ func (e PeerEndpoint) RegisterRoutes(g *routegroup.Bundle) { apiGroup := g.Mount("/peer") apiGroup.Use(e.authenticator.LoggedIn()) - apiGroup.With(e.authenticator.LoggedIn(ScopeAdmin)).HandleFunc("GET /by-interface/{id}", + apiGroup.With(e.authenticator.LoggedIn(ScopeAdmin)).HandleFunc("GET /by-interface/{id...}", e.handleAllForInterfaceGet()) - apiGroup.HandleFunc("GET /by-user/{id}", e.handleAllForUserGet()) - apiGroup.HandleFunc("GET /by-id/{id}", e.handleByIdGet()) + apiGroup.HandleFunc("GET /by-user/{id...}", e.handleAllForUserGet()) + apiGroup.HandleFunc("GET /by-id/{id...}", e.handleByIdGet()) - apiGroup.With(e.authenticator.LoggedIn(ScopeAdmin)).HandleFunc("GET /prepare/{id}", e.handlePrepareGet()) + apiGroup.With(e.authenticator.LoggedIn(ScopeAdmin)).HandleFunc("GET /prepare/{id...}", e.handlePrepareGet()) apiGroup.With(e.authenticator.LoggedIn(ScopeAdmin)).HandleFunc("POST /new", e.handleCreatePost()) - apiGroup.With(e.authenticator.LoggedIn(ScopeAdmin)).HandleFunc("PUT /by-id/{id}", e.handleUpdatePut()) - apiGroup.With(e.authenticator.LoggedIn(ScopeAdmin)).HandleFunc("DELETE /by-id/{id}", e.handleDelete()) + apiGroup.With(e.authenticator.LoggedIn(ScopeAdmin)).HandleFunc("PUT /by-id/{id...}", e.handleUpdatePut()) + apiGroup.With(e.authenticator.LoggedIn(ScopeAdmin)).HandleFunc("DELETE /by-id/{id...}", e.handleDelete()) } // handleAllForInterfaceGet returns a gorm Handler function. diff --git a/internal/app/api/v1/handlers/endpoint_user.go b/internal/app/api/v1/handlers/endpoint_user.go index 28902eb..32dec1f 100644 --- a/internal/app/api/v1/handlers/endpoint_user.go +++ b/internal/app/api/v1/handlers/endpoint_user.go @@ -47,10 +47,10 @@ func (e UserEndpoint) RegisterRoutes(g *routegroup.Bundle) { apiGroup.Use(e.authenticator.LoggedIn()) apiGroup.With(e.authenticator.LoggedIn(ScopeAdmin)).HandleFunc("GET /all", e.handleAllGet()) - apiGroup.HandleFunc("GET /by-id/{id}", e.handleByIdGet()) + apiGroup.HandleFunc("GET /by-id/{id...}", e.handleByIdGet()) apiGroup.With(e.authenticator.LoggedIn(ScopeAdmin)).HandleFunc("POST /new", e.handleCreatePost()) - apiGroup.With(e.authenticator.LoggedIn(ScopeAdmin)).HandleFunc("PUT /by-id/{id}", e.handleUpdatePut()) - apiGroup.With(e.authenticator.LoggedIn(ScopeAdmin)).HandleFunc("DELETE /by-id/{id}", e.handleDelete()) + apiGroup.With(e.authenticator.LoggedIn(ScopeAdmin)).HandleFunc("PUT /by-id/{id...}", e.handleUpdatePut()) + apiGroup.With(e.authenticator.LoggedIn(ScopeAdmin)).HandleFunc("DELETE /by-id/{id...}", e.handleDelete()) } // handleAllGet returns a gorm Handler function.