You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RFC: Extract optional serialization formats from Gin core into gin-contrib
#4774
If there's interest, I can follow up with a more detailed technical design (registry interfaces, Negotiate behavior, and a before/after dependency diff).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Move optional serialization formats to
gin-contrib(Gin v2 proposal)Category: Ideas
Labels (optional):
proposal,v2,dependencies,breaking-changeTL;DR
I'm proposing we slim down Gin core by moving optional serialization formats into
gin-contribmodules:encoding/json/v2), XML, form/query/URI binding, HTML renderBackground
Importing
github.com/gin-gonic/gintoday pulls in many third-party serialization libraries, even if a project only uses JSON:goccy/go-yamlpelletier/go-toml/v2google.golang.org/protobufgo.mongodb.org/mongo-driver/v2ugorji/go/codecsonic/json-iterator/goccy/go-jsonThis affects us in two ways:
go.mod/ SBOM, whether or not they're used.bindingandrenderare always linked fromcontext.go, so YAML/TOML/BSON/Protobuf/MsgPack get compiled in even for JSON-only apps.Gin already has patterns that point in this direction:
nomsgpackbuild tag to drop MsgPack at compile timesonic,go_json,jsoniter) — only one backend is linked, but all remain ingo.modWith
encoding/json/v2on the horizon (golang/go#71497), this feels like a good time to simplify JSON in core and treat everything else as opt-in.Proposal
Gin v2 core stays lean
Optional formats move to
gin-contribSuggested modules (names TBD):
gin-contrib/format-yamlgin-contrib/format-tomlgin-contrib/format-bsongin-contrib/format-protobufgin-contrib/format-msgpackgin-contrib/codec-sonicgin-contrib/codec-gojsongin-contrib/codec-jsoniterRegistration model (sketch)
Instead of hard-coded package vars in
binding/binding.go, v2 would use something like:Contrib modules register both binding and render in
init(), similar todatabase/sqldrivers.Migration plan (avoid a Python 2/3 situation)
noyaml,notoml,nobson, … (likenomsgpack)github.com/gin-gonic/gin/v2, registry API, formats in contribv1 and v2 would coexist under different import paths — not a forced ecosystem split.
What would break in v2
binding.YAML,binding.TOML,binding.BSON, …BindYAML,c.YAML(),c.TOML(),c.BSON(), MsgPack render, etc.Negotiate()branches for formats not in coreContrib modules could provide thin wrappers to preserve ergonomics:
Expected benefits
go.mod/ SBOM surface for JSON-only projectsencoding/json/v2in core without carrying legacy JSON backendsAlternatives
go get— doesn't fix transitive deps.Questions for the community
I'd love maintainer and user feedback on these:
format-yaml) vs split binding/render modules?Negotiate(): skip unregistered formats silently, or return a clear error?encoding/json/v2GA, or ship with stdlib v1 JSON first?quic-go): separate RFC, or include in the same slimming effort?c.BindYAML, etc.), or is explicit registration enough?References
nomsgpackbuild tag (see README)If there's interest, I can follow up with a more detailed technical design (registry interfaces,
Negotiatebehavior, and a before/after dependency diff).What's your take?
All reactions