Skip to content

refactor: use Go 1.22's ServeMux path patterns instead gorilla/mux#684

Draft
benhoyt wants to merge 3 commits into
canonical:masterfrom
benhoyt:remove-gorilla/mux
Draft

refactor: use Go 1.22's ServeMux path patterns instead gorilla/mux#684
benhoyt wants to merge 3 commits into
canonical:masterfrom
benhoyt:remove-gorilla/mux

Conversation

@benhoyt

@benhoyt benhoyt commented Aug 20, 2025

Copy link
Copy Markdown
Contributor

DRAFT: not yet ready for review. And I still need to figure out how this applies to snapd and run it past them.

See also: draft of using Copilot to do this in the snapd repo

Oddly, it doesn't decrease the binary size. In fact, building with the flags we use to build the snap, it's very slightly bigger (exactly 4096 = 4KB). Not sure why, maybe something's bumped it into using another 4KB "page".

In terms of performance, routing is 30% faster, and does fewer memory allocations. Not that that is a big driver here, both are at the millisecond level. But here are the numbers of this benchmark:

          │ router_gorilla.txt │         router_servemux.txt         │
          │       sec/op       │   sec/op     vs base                │
Router-16          2.699µ ± 6%   1.850µ ± 7%  -31.44% (p=0.000 n=10)

          │ router_gorilla.txt │         router_servemux.txt          │
          │        B/op        │     B/op      vs base                │
Router-16         3.406Ki ± 0%   2.574Ki ± 0%  -24.43% (p=0.000 n=10)

          │ router_gorilla.txt │        router_servemux.txt         │
          │     allocs/op      │ allocs/op   vs base                │
Router-16           31.00 ± 0%   24.00 ± 0%  -22.58% (p=0.000 n=10)

Fixes #676.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Refactors Pebble's HTTP routing from gorilla/mux to Go 1.22's native ServeMux path patterns to improve performance and reduce dependencies.

  • Replaced gorilla/mux with http.ServeMux for HTTP routing
  • Updated path parameter extraction from muxVars(req)["param"] to req.PathValue("param")
  • Simplified path patterns to match ServeMux syntax (e.g., {task-id} to {taskID})

Reviewed Changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internals/daemon/daemon.go Replace mux.Router with http.ServeMux and simplify route registration
internals/daemon/api.go Remove mux dependency and update path patterns to use camelCase
internals/daemon/api_changes.go Update parameter extraction to use req.PathValue()
internals/daemon/api_notices.go Update parameter extraction to use req.PathValue()
internals/daemon/api_tasks.go Update parameter extraction to use req.PathValue()
internals/daemon/daemon_test.go Refactor tests to use HTTP requests instead of mux internals
internals/daemon/export_test.go Remove mux-related test utilities
internals/daemon/api_test.go Remove mux test setup and helper functions
internals/daemon/api_changes_test.go Update tests to use req.SetPathValue()
internals/daemon/api_notices_test.go Update tests to use req.SetPathValue()
go.mod Remove gorilla/mux dependency
docs/specs/openapi.yaml Update API documentation to reflect new path patterns
docs/explanation/api-and-clients.md Update documentation examples
HACKING.md Remove mux import from example code

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internals/daemon/daemon.go
Path string
PathPrefix string
//
Path string

Copilot AI Nov 3, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PathPrefix field has been removed from the Command struct, but there's no clear indication of how prefix-based routing is now handled. If any commands previously used PathPrefix, this could be a breaking change.

Suggested change
Path string
Path string
PathPrefix string

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace gorilla/mux with http.ServeMux path patterns

2 participants