本文整理匯總了Golang中github.com/gin-gonic/gin.Context.EnsureBody方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.EnsureBody方法的具體用法?Golang Context.EnsureBody怎麽用?Golang Context.EnsureBody使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gin-gonic/gin.Context
的用法示例。
在下文中一共展示了Context.EnsureBody方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: LoginPost
func LoginPost(ctx *gin.Context) {
// create a new Beego ORM object
o := orm.NewOrm()
o.Using("default")
// initialize our data structs
data := LoginData{}
user := models.Users{}
// expecting our login data in JSON form
ctx.EnsureBody(&data)
// search the users table for the first user with an email and password we supplied
// of course storing passwords in plaintext is stupid, this is just an example
err := o.QueryTable("users").Filter("email", data.Email).Filter("password", data.Password).One(&user)
if err != nil {
ctx.String(400, "User was not found!")
return
}
// this data will be added to the cookie and available on decode
extra := map[string]string{"email": data.Email}
// log in the user
err1 := auth.Login(ctx, extra)
if err1 == nil {
ctx.String(200, "")
}
}