How to log or print request received with gin?

12,581

Just read and print the body is ok:

func createOrUpdateInfluencer(c *gin.Context) {
    body, _ := ioutil.ReadAll(c.Request.Body)
    println(string(body))
}

Or if you just want to peek it in middleware, you can put it back after read:

func createOrUpdateInfluencer(c *gin.Context) {
    body, _ := ioutil.ReadAll(c.Request.Body)
    println(string(body))

    c.Request.Body = ioutil.NopCloser(bytes.NewReader(body))
}
Share:
12,581
Bussiere
Author by

Bussiere

Updated on June 05, 2022

Comments

  • Bussiere
    Bussiere almost 2 years

    Example:

    func createOrUpdateInfluencer(c *gin.Context) { }
    

    How to print the data in the request received in my function? In my case, I am supposed to receive JSON, how to print it without knowing what it looks like?