【ジンフレーム】ジンパラメータバインディング

package main 

import(
   "fmt" 
   "github.com/gin-gonic/gin" 
   "net / http" 
type UserInfo struct {
   ユーザー名文字列 `form:" username "`
   パスワード文字列 `form:" password "` 
} 
func main( ){ 
   r:= gin.Default()

   r.POST( "/ form"、func(c * gin.Context){ 
      var u UserInfo 
      //参数绑定
      err:= c.ShouldBind(&u)
      if err!= nil { 
         c.JSON(http.StatusBadRequest、gin.H { 
            "error:":err.Error()、
         })
      } else { 
         fmt.Println( "%#v \ n"、u)
         c.JSON(http.StatusOK 、gin.H { 
            "status": "ok"、
         })
      } 
   })

   r.Run()
}

おすすめ

転載: blog.csdn.net/qq2942713658/article/details/112712324