• 只绑定 url 查询字符串

    只绑定 url 查询字符串

    ShouldBindQuery 函数只绑定 url 查询参数而忽略 post 数据。参阅详细信息.

    1. package main
    2. import (
    3. "log"
    4. "github.com/gin-gonic/gin"
    5. )
    6. type Person struct {
    7. Name string `form:"name"`
    8. Address string `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. }