-1

In GIN POST method, BindJSON omitting a single quote in the request body field
Here is my POST method

func TestPost(c *gin.Context) {
    var tmp struct{ Tmp string }
    c.BindJSON(&tmp)
    log.Printf("%+v\n", tmp)
    /* my work */
    c.Status(200)
}

Here is my CURL request

curl -X POST localhost:5005 --data '{"tmp":"example string 'GIN' have single quote"}'

In GIN Log

2020/04/15 11:35:39 {Tmp:example string GIN have single quote}

[GIN] 2020/04/15 - 11:35:39 | 200 | 209.71µs | 127.0.0.1 | POST "/"

As you can see in the logs, GIN does not have single quotes around it My use case is to preserve the single quote that is passed as a payload

Please help !!!

Community
  • 1
  • 1
Dharaneesh Vrd
  • 190
  • 2
  • 11

1 Answers1

0

The problem is with CURL

curl -X POST localhost:5005 --data '{"tmp":"example string '\''GIN'\'' have single quote"}'
Dharaneesh Vrd
  • 190
  • 2
  • 11