Skip to content

Instantly share code, notes, and snippets.

@kuku
Last active November 19, 2020 07:04
Show Gist options
  • Save kuku/f00e3e8a38b3ac6effb2d1bf3c17e6c7 to your computer and use it in GitHub Desktop.
Save kuku/f00e3e8a38b3ac6effb2d1bf3c17e6c7 to your computer and use it in GitHub Desktop.
在 gin 中读取 body 中的 json 数据
// https://pkg.go.dev/github.com/gin-gonic/gin#Context.BindJSON
type Params struct {
PostName string `json:"postName"`
}
r.POST("/", func(c *gin.Context) {
var someParams Params
err := c.BindJSON(&someParams)
if err != nil {
log.Fatal(err)
}
fmt.Println(createParams)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment