Only Bind Query String

ShouldBindQuery function only binds the query params and not the post data. See the detail information.

  1. package main
  2. import(
  3. "log"
  4. "github.com/gin-gonic/gin"
  5. )
  6. type Personstruct{
  7. Namestring`form:"name"`
  8. Addressstring`form:"address"`
  9. }
  10. func main(){
  11. route := gin.Default()
  12. route.Any("/testing", startPage)
  13. route.Run(":8085")
  14. }
  15. func startPage(c *gin.Context){
  16. var person Person
  17. if c.ShouldBindQuery(&person)==nil{
  18. log.Println("====== Only Bind By Query String ======")
  19. log.Println(person.Name)
  20. log.Println(person.Address)
  21. }
  22. c.String(200,"Success")
  23. }