Skip to content

Comments

feat(binding): add support for binding whole request at once#4543

Open
takanuva15 wants to merge 1 commit intogin-gonic:masterfrom
takanuva15:master
Open

feat(binding): add support for binding whole request at once#4543
takanuva15 wants to merge 1 commit intogin-gonic:masterfrom
takanuva15:master

Conversation

@takanuva15
Copy link
Contributor

@takanuva15 takanuva15 commented Feb 19, 2026

With this PR, users can now call c.BindAll allow Gin to bind headers, request path params, query params, and body in a single call. This resolves a number of tickets regarding this functionality:

relates to #1824
relates to #2309
closes #2535
closes #2758
closes #2919
closes #4338
closes #3095
closes #4510

MVE:

package main

import (
  "net/http"

  "github.com/gin-gonic/gin"
)

type Person struct {
  Age       int       `header:"x-age" binding:"required"`
  ID        string    `uri:"id" binding:"required,uuid"`
  Name      string    `form:"name" binding:"required"`
  Addresses [2]string `json:"addresses" binding:"required"`
}

func main() {
  route := gin.Default()
  route.POST("/:id", func(c *gin.Context) {
    var person Person
    if err := c.ShouldBindAll(&person); err != nil {
      c.JSON(http.StatusBadRequest, gin.H{"msg": err.Error()})
      return
    }
    c.JSON(http.StatusOK, person)
  })
  route.Run(":8080")
}

Test it with:

curl -X POST -H "x-age:25" -H "Content-Type: application/json" -d '{"addresses":["foo","bar"]}' 'http://localhost:8080/987fbc97-4bed-5078-9f07-9141ba07c9f3?name=Bob'
# {"Age":25,"ID":"987fbc97-4bed-5078-9f07-9141ba07c9f3","Name":"Bob","addresses":["foo","bar"]}

Pull Request Checklist

Please ensure your pull request meets the following requirements:

  • Open your pull request against the master branch.
  • All tests pass in available continuous integration systems (e.g., GitHub Actions).
  • Tests are added or modified as needed to cover code changes.
  • If the pull request introduces a new feature, the feature is documented in the docs/doc.md.

Thank you for contributing!

@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.01%. Comparing base (3dc1cd6) to head (be6e758).
⚠️ Report is 249 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4543      +/-   ##
==========================================
- Coverage   99.21%   99.01%   -0.21%     
==========================================
  Files          42       46       +4     
  Lines        3182     3040     -142     
==========================================
- Hits         3157     3010     -147     
- Misses         17       21       +4     
- Partials        8        9       +1     
Flag Coverage Δ
?
--ldflags="-checklinkname=0" -tags sonic 99.01% <100.00%> (?)
go-1.18 ?
go-1.19 ?
go-1.20 ?
go-1.21 ?
go-1.25 99.01% <100.00%> (?)
macos-latest 99.01% <100.00%> (-0.21%) ⬇️
ubuntu-latest ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant