ShouldBindBody, when used as as described in the README, throws a compile error.

Description

According to the readme I should be able to use c.ShouldBindBodyWith(&objA, binding.JSON) to get a copy of the request body. But the code in the README results in a compiler error. And, rightfully so, because binding.JSON is assigned to a private struct: https://github.com/gin-gonic/gin/blob/master/binding/binding.go#L71

Am I reading the README wrong? Should I not use ShouldBindBodyWith? How would I copy the request body and still be able to use it a second time without having to reset the body in the request.

How to reproduce

Copy and paste the code below and run go run main.go. That will produce the compiler error.

package main

import (
	"github.com/gin-gonic/gin"
	"github.com/gin/binding"
)

func main() {
	g := gin.Default()
	g.GET("/hello/:name", func(c *gin.Context) {

		// Compile error happens below. The nil value is just there to satisfy
		// the method signature. 
		c.ShouldBindBodyWith(nil, binding.JSON)
		c.String(200, "Hello %%s", c.Param("name"))
	})
	g.Run(":9000")
}

Expectations

I expected the code above to compile.

Actual result

Results in a compile error:

go/src/github.com/gin/binding/form_mapping.go:14:2: use of internal package github.com/gin-gonic/gin/internal/json not allowed## Environment

  • go version: 1.13
  • gin version (or commit ref):
  • operating system: OSX

1 possible answer(s) on “ShouldBindBody, when used as as described in the README, throws a compile error.