gin中multipart/urlencoded绑定
package main import (
"fmt"
"github.com/gin-gonic/gin"
"net/http"
) type LoginForm struct {
// form:"user" 表示前端提交form表单时User对应的key的名称为:user
// binding: "required" required表示前端必须传入该键才可以
User string `form:"user" binding:"required"`
Password string `form:"password" binding:"required"`
} func main() {
router := gin.Default()
router.POST("/login", func(c *gin.Context) {
var form LoginForm
// 你可以使用显示绑定声明绑定 multipart form
//if err := c.ShouldBindWith(&form, binding.Form); err == nil {
// 先校验用户传参是否符合LoginForm的校验约束
// 或者简单的使用ShouldBind方法自动绑定,在这种情况下将自动选择合适的绑定
if err := c.ShouldBind(&form); err == nil {
// 在校验传入的用户名密码是否正确
if form.User == "user" && form.Password == "password" {
c.JSON(http.StatusOK, gin.H{"status": "you are logged int"})
} else {
c.JSON(http.StatusUnauthorized, gin.H{"status": "Unauthorized"})
}
} else {
fmt.Println(err)
c.JSON(http.StatusBadRequest, gin.H{"key": "key error"})
}
})
router.Run()
}
gin中multipart/urlencoded绑定的更多相关文章
- gin中multipart/urlencoded表单
package main import ( "github.com/gin-gonic/gin" ) func main() { router := gin.Default() r ...
- gin中模型的绑定和验证
要将请求体绑定到结构体中,使用模型绑定. Gin目前支持JSON.XML.YAML和标准表单值的绑定(foo=bar&boo=baz). Gin使用 go-playground/validat ...
- jQuery中的事件绑定方法
在jQuery中,事件绑定方法大致有四种:bind(),live(), delegate(),和on(). 那么在工作中应该如何选择呢?首先要了解四种方法的区别和各自的特点. 在了解这些之前,首先要知 ...
- MVC中Action参数绑定的过程
一.题外话 上一篇:MVC中Action的执行过程 ControllerContext 封装有了与指定的 RouteBase 和 ControllerBase 实例匹配的 HTTP 请求的信息. 二. ...
- activity中实现Spinner绑定
(1)须要一个基本的布局文件activity_main <RelativeLayout xmlns:android="http://schemas.android.com/apk/re ...
- Jquery中的事件绑定$("#btn").bind("click",function(){ })
Jquery中的事件绑定:$("#btn").bind("click",function(){ }) 由于每次都这么调用太麻烦,所以jquery就用$(&qu ...
- Asp.net Mvc 中的模型绑定
asp.net mvc中的模型绑定可以在提交http请求的时候,进行数据的映射. 1.没有模型绑定的时候 public ActionResult Example0() { ) { string id ...
- AngularJS中数据双向绑定(two-way data-binding)
1.切换工作目录 git checkout step-4 #切换分支,切换到第4步 npm start #启动项目 2.代码 app/index.html Search: <input ng-m ...
- jQuery 中的事件绑定
一.事件概念 和数据库中的触发器一样,当操作了数据的时候会引发对应的触发器程序执行 一样,JS 中的事件就是对用户特定的行为作出相应的响应的过程,其实上就是浏览器 监听到用户的某些行为的时候会执行对应 ...
随机推荐
- Linux(centos)使用nc命令发送测试数据
安装 yum -y install nmap-ncat 简单使用 nc -lk 7777 # 开启一个本地7777的TCP协议端口,由客户端主动发起连接,一旦连接必须由服务端发起关闭 nc -vw 2 ...
- JAVA中json对象转JAVA对象,JSON数组(JSONArray)转集合(List)
json格式 {userId:'1',message:'2',create_time:'2020-03-28 20:58:11',create_date:'2020-03-28'}JAVA对象 Cha ...
- 【LeetCode】1221. Split a String in Balanced Strings 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 统计 日期 题目地址:https://leetcode ...
- 【LeetCode】735. Asteroid Collision 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 栈 日期 题目地址:https://leetcode ...
- GCD - Extreme (II)(UVA11426)
思路:欧拉函数: 欧拉函数,然后用下等差数列公式就行了. 1 #include<stdio.h> 2 #include<algorithm> 3 #include<ios ...
- Doing Homework(hdu)1074
Doing Homework Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- 自我学习与理解:keras框架下的深度学习(三)回归问题
本文主要是使用keras对其有的波士顿房价数据集做一个回归预测,其代码架构与之前一样(都只是使用多层感知机):数据的预处理.搭建网络框架.编译.循环训练以及测试训练的网络模型.其中除了数据预处理与之前 ...
- POJ 1986:Distance Queries
Distance Queries Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 18139 Accepted: 6248 ...
- Simplicial principal component analysis for density functions in Bayes spaces
目录 问题 上的PCA Hron K, Menafoglio A, Templ M, et al. Simplicial principal component analysis for densit ...
- uniapp动态修改导航栏
1.修改导航栏buttons 如图动态修改角标 <template> <view> </view> </template> <script> ...