I new using Go, I have a problem how to get post request on Go. I was searching but still can't solve the problem
I was trying json.Unmarshal() but still not working
package controllers
import (
"encoding/json"
"net/http"
"github.com/gin-gonic/gin"
)
//CreateOrder function
func CreateOrder(c *gin.Context) {
var requestBody struct {
TransNo string `json:"trans_no"`
}
err := json.NewDecoder(c.Request.Body).Decode(&requestBody)
if err != nil {
panic(err)
}
c.JSON(http.StatusOK, gin.H{"data": requestBody.TransNo})
}
I no have any errors, but the result not showing anything.
this my post data :
{
"transaction_details": {
"trans_no": "12400099",
"gross_amount": 50000
}
}
I wont to get trans_no value