gin-gonic / gin-gonic/examples
body is null in LoggerWithFormatter
Open
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 4.6k
- Forks
- 726
- Avg merge
- 2h 23m
- Merged PRs (30d)
- 3
Description
i have a problems when i try loggin del body because de body is null
gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string {
body, err := ioutil.ReadAll(param.Request.Body)
the problem is in my controller i have this code
var body entities.WriteChatRequest
if err := c.ShouldBindJSON(&body); err != nil {
c.JSON(400, gin.H{"error": err.Error()})
return
}
the body was converted but now is null, when the controller finished and i try logging
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the example that configures gin.LoggerWithFormatter and the controller using ShouldBindJSON. Reproduce the request, then inspect how the request body is handled by the binding and logging paths. Done means the example can log the submitted body after the controller has processed it without a null body.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100