Repository navigation
refactor(integration)!: move echo integration into its own package - #135
alecsammon wants to merge 4 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #135 +/- ##
=======================================
Coverage 91.12% 91.12%
=======================================
Files 36 36
Lines 1307 1307
=======================================
Hits 1191 1191
Misses 72 72
Partials 44 44
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
04e56e8 to
b1ee2cc
Compare
The echo integration is the only one that takes a concrete router type (*echo.Echo). gochi, gorilla and http all accept function values, so they carry no third-party dependencies at all. Because Go's unit of dependency is the package, importing `integration` for chi or gorilla pulls echo — and gommon, fasttemplate, bytebufferpool, colorable and isatty — into every consumer's module graph. Moving it to `integration/echo` leaves the dependency-free integrations where they are and confines echo to the users who actually want it. BREAKING CHANGE: echo users must import github.com/ggicci/httpin/integration/echo instead of github.com/ggicci/httpin/integration.
b1ee2cc to
a107663
Compare
|
Taking a look. |
TestingWith this change, we still have echo in the root module of httpin package, see: Create a customer package with a package main
import (
"github.com/ggicci/httpin/integration"
"github.com/go-chi/chi/v5"
)
func main() {
integration.UseGochiURLParam("path", chi.URLParam)
}We expect This means this change didn't resolve the problem it intended to. |
|
Updating code to create a nested module for echo. |
|
TODO: release and update docs |
| @@ -0,0 +1,23 @@ | |||
| module github.com/ggicci/httpin/integration/echo | |||
|
|
|||
| go 1.26.5 | |||
There was a problem hiding this comment.
your base package is still go 1.25.0
Does it make sense to keep this to the same version?
|
Thank you for picking this up! Sorry - had opened a draft PR to explore - wasn't expecting you to fix all the problems! |
THIS IS A BREAKING CHANGE - I am still thinking if the there is a better way through. Will bring it out of draft when I'm happy!
This PR was generated with AI.
I have left the original description below, but thought good to explain in my own terms (and prove I know what this is doing!)
When you import
integration.UseGochiURLParamthen it drags ingithub.com/labstack/echo/v4This has a large number of indirect dependencies, and an open CVE.
This dependency is only used for a test.
By moving the test into a sub-package - then it drops out of the dependencies when you import the package. This means the labstack/echo is no longer included.
--
Why
integrationis a single package, and Go's unit of dependency is the package. So importing it for the chi, gorilla or net/http integration also pulls in Echo.That asymmetry isn't deliberate — it falls out of one design difference:
UseGochiURLParamchi.URLParamas a func valueUseGorillaMuxmux.Varsas a func valueUseHttpPathVariableUseEchoRouter*echo.Echolabstack/echo/v4echo.gois the only non-test file in the package that imports a router. Everyone else pays for it.What it costs today
A consumer that imports
integrationpurely forUseGochiURLParam:Before —
go mod tidyrecords 11 indirect dependencies:After — one:
None of it was ever linked into the binary — the linker drops it — but it is recorded in every consumer's
go.mod, which is what Dependabot reads for Go modules. Consumers'go.sumsheds it too (16 lines, down from 36). So each Echo CVE raises a bump on codebases that have never constructed anecho.Echo. GHSA-vfp3-v2gw-7wfq, for instance, is in the static file handler and is unreachable for anyone not serving files with Echo.What this changes
echo.goandecho_test.gomove tointegration/echo. Nothing else moves: the other three integrations carry no dependencies, so they belong exactly where they are. Git renders both files as renames — the edits are the package clause, an import alias, the import path in the doc comment, and a four-line test fixture that was previously shared withgorilla_test.go.go.modfor this module is unchanged — Echo is still a direct requirement, becauseintegration/echogenuinely uses it. The difference is that downstream module graphs only include it when they import that package.Migration
One import line:
I kept the name
UseEchoRouterrather than shortening it toUse, to keep the diff and the docs churn minimal — happy to rename if you'd preferhttpin_echo.Use.The docs at
ggicci.github.io/httpin/integrations/echowill need the same one-line update; let me know if that lives somewhere I can send a patch.Verification
go build ./...,go vet ./...andgo test -race -failfast ./...all pass locally, and this branch is green on CI —integration/echoreports 100% coverage.go.modandgo.sumare untouched; the diff is two files, both renames.The before/after dependency counts above were measured with a scratch consumer module against this branch and against
main: 11 indirect requirements and a 36-linego.sumonmain, 1 and 16 on this branch.Raised as a draft — it is a breaking change to a public import path, so I'd rather check you want it at all before polishing. Happy to close it if this is a trade you'd rather not make.
🤖 Generated with Claude Code