gin-gonic / gin-gonic/examples

body is null in LoggerWithFormatter

Open
#68 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.