From 6833feee87757e3027a2fe9cde1e46aca9edd90a Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 12 Oct 2026 19:14:45 +0200 Subject: [PATCH] pkg/api: replace github.com/gorilla/mux with stdlib Signed-off-by: Sebastiaan van Stijn --- go.mod | 1 - go.sum | 2 -- pkg/api/router/router.go | 18 ++++++------------ pkg/parent/parent.go | 3 +-- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index 8497171b..3b86fbc0 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( github.com/containers/gvisor-tap-vsock v0.8.9 github.com/gofrs/flock v0.13.1 github.com/google/uuid v1.6.0 - github.com/gorilla/mux v1.8.1 github.com/inetaf/tcpproxy v0.0.0-20260515195445-c159a6051109 github.com/insomniacslk/dhcp v0.0.0-20260901064844-234b97448fae github.com/moby/sys/mountinfo v0.7.2 diff --git a/go.sum b/go.sum index 070d01d0..815febf3 100644 --- a/go.sum +++ b/go.sum @@ -33,8 +33,6 @@ github.com/google/pprof v0.0.0-20250820193118-f64d9cf942d6 h1:EEHtgt9IwisQ2AZ4pI github.com/google/pprof v0.0.0-20250820193118-f64d9cf942d6/go.mod h1:I6V7YzU0XDpsHqbsyrghnFZLO1gwK6NPTNvmetQIk9U= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= -github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= github.com/inetaf/tcpproxy v0.0.0-20260515195445-c159a6051109 h1:H3ztMPCBcyG60Ks0plTncU3Vs6jIrxhn3nEThpMEpo4= github.com/inetaf/tcpproxy v0.0.0-20260515195445-c159a6051109/go.mod h1:Di7LXRyUcnvAcLicFhtM9/MlZl/TNgRSDHORM2c6CMI= github.com/insomniacslk/dhcp v0.0.0-20260901064844-234b97448fae h1:nXGg65fXsylSUTNNWwvHuQsXev7mhIzQTnZREPTbWzs= diff --git a/pkg/api/router/router.go b/pkg/api/router/router.go index b4c522fc..4b8cf16e 100644 --- a/pkg/api/router/router.go +++ b/pkg/api/router/router.go @@ -8,7 +8,6 @@ import ( "net/http" "strconv" - "github.com/gorilla/mux" "github.com/rootless-containers/rootlesskit/v3/pkg/api" "github.com/rootless-containers/rootlesskit/v3/pkg/httputil" "github.com/rootless-containers/rootlesskit/v3/pkg/port" @@ -94,11 +93,7 @@ func (b *Backend) DeletePort(w http.ResponseWriter, r *http.Request) { b.onPortDriverNil(w, r) return } - idStr, ok := mux.Vars(r)["id"] - if !ok { - httputil.WriteError(w, r, errors.New("id not specified"), http.StatusBadRequest) - return - } + idStr := r.PathValue("id") id, err := strconv.Atoi(idStr) if err != nil { httputil.WriteError(w, r, fmt.Errorf("bad id %s: %w", idStr, err), http.StatusBadRequest) @@ -144,10 +139,9 @@ func (b *Backend) GetInfo(w http.ResponseWriter, r *http.Request) { w.Write(m) } -func AddRoutes(r *mux.Router, b *Backend) { - v1 := r.PathPrefix("/v1").Subrouter() - v1.Path("/ports").Methods("GET").HandlerFunc(b.GetPorts) - v1.Path("/ports").Methods("POST").HandlerFunc(b.PostPort) - v1.Path("/ports/{id}").Methods("DELETE").HandlerFunc(b.DeletePort) - v1.Path("/info").Methods("GET").HandlerFunc(b.GetInfo) +func AddRoutes(r *http.ServeMux, b *Backend) { + r.HandleFunc("GET /v1/ports", b.GetPorts) + r.HandleFunc("POST /v1/ports", b.PostPort) + r.HandleFunc("DELETE /v1/ports/{id}", b.DeletePort) + r.HandleFunc("GET /v1/info", b.GetInfo) } diff --git a/pkg/parent/parent.go b/pkg/parent/parent.go index 2de738b3..8fa96251 100644 --- a/pkg/parent/parent.go +++ b/pkg/parent/parent.go @@ -15,7 +15,6 @@ import ( "syscall" "github.com/gofrs/flock" - "github.com/gorilla/mux" "github.com/rootless-containers/rootlesskit/v3/pkg/api/router" "github.com/rootless-containers/rootlesskit/v3/pkg/messages" "github.com/rootless-containers/rootlesskit/v3/pkg/network" @@ -503,7 +502,7 @@ type apiCloser interface { } func listenServeAPI(socketPath string, backend *router.Backend) (apiCloser, error) { - r := mux.NewRouter() + r := http.NewServeMux() router.AddRoutes(r, backend) srv := &http.Server{Handler: r} err := os.RemoveAll(socketPath)