草庐IT

Form_Validation

全部标签

validation - gin-gonic 中的多部分文件上传验证

我正在尝试为基于GIN框架的基于go的Web应用程序添加验证。在网页上,我正在选择一个文件并提交,服务器正在处理它。在服务器端,我尝试添加验证以检查文件是否已提供。如果没有,则重定向回原始页面。funcpanic(errerror){iferr!=nil{log.Println(err)}}funcdisplayTable(c*gin.Context){file,_,err:=c.Request.FormFile("file")panic(err)iffile==nil{log.Println("Fileisnil.")log.Println(err)log.Println("****

pointers - go中的form参数为map时,传入的是什么?

当形参为map时,直接给形参赋值并不能改变实参,但是如果给形参增加新的key和value,函数外的实参也是可以看到的。这是为什么?看不懂下面代码的输出值,形参和实参不一样。uncmain(){t:=map[int]int{1:1,}fmt.Println(unsafe.Pointer(&t))copysss(t)fmt.Println(t)}funccopysss(mmap[int]int){//pointer:=unsafe.Pointer(&m)//fmt.Println(pointer)m=map[int]int{1:2,}}stdout:0xc000086010map[1:1]

戈朗 : convert IPv4 and IPv6 addresses from text to binary form

希望发送4个字节的ipv4地址和16个字节的ipv6地址-类似于inet_pton()去吗?structsockaddr_insa;charstr[INET_ADDRSTRLEN];inet_pton(AF_INET,"192.0.2.33",&(sa.sin_addr));structsockaddr_in6sa;charstr[INET6_ADDRSTRLEN];inet_pton(AF_INET6,"2001:db8:8714:3a90::12",&(sa.sin6_addr));我知道https://play.golang.org/p/jn8t7zJzT5v-虽然IPV6地址看

validation - beego 验证接受无效数据

我正在尝试使用Beego验证来验证某些表单,但它根本不起作用:无效数据通过且没有错误。这是相关代码,我不知道哪里出了问题。你能指出错误吗?https://github.com/dionyself/golang-cms/blob/master/models/form.gopackagemodelsimport("github.com/astaxie/beego""github.com/astaxie/beego/validation")typeBaseFormstruct{Errorsmap[string]string}func(form*BaseForm)Validate()bool{

validation - 结合 GO GIN-GONIC GORM 和 VALIDATOR.V2

我是Go的新手,我想通过设置GIN-GONICAPI来启动。我找到了这个tutorial我对那个骨架很满意。但现在我坚持使用我添加的验证过程:“gopkg.in/validator.v2”和typeTodostruct{gorm.ModelTitlestring`json:"title"`Completedint`json:"completed"`}成为typeTodostruct{gorm.ModelTitlestring`json:"title"**validate:"size:2"**`Completedint`json:"completed"`}然后在我添加的CreateTod

go - 使用 gin 包从 Postman Form 获取数据后没有显示任何值

下面是我正在处理的代码。它在运行时显示一条成功消息,但不显示postman表单中定义的值。相反,它在命令提示符中显示空格。packagemainimport("fmt""github.com/gin-gonic/gin")funcsaveCustomer(c*gin.Context){fn:=c.PostForm("firstName")ln:=c.PostForm("lastName")em:=c.PostForm("email")phnno:=c.PostForm("phone_no")fmt.Printf("fn:%v;ln:%v;em:%v;phnno:%v;",fn,ln,e

go - 后操作失败,出现 "CSRF token validation failed"错误

我正在尝试对SAPHybrisC4C实体执行POST操作。我看到很多博客提到我们需要在POST期间发送X-CSRF-Token,它可以首先使用GET操作检索。我使用Postman成功地做到了这一点。因为Postman存储cookie不会导致CSRFtoken验证失败。但是,我实际上想用golang来调用它。而且我每次都收到错误,因为“CSRFtoken验证失败”。然后在浏览了很多博客之后,我发现我们不仅要设置X-CSRF-Token,还要设置Cookie,这样HTTPPOST就不会被视为新session。否则我们发送的csrftoken与当前session不匹配导致错误。即使按照以上两

validation - Golang 验证器多字段依赖

我想验证以下结构:typeCarModelstruct{gorm.ModelOwnerIDint`json:"ownerid"validate:"nonzero"`Typestring`json:"type"validate:"regexp=(?)(A|B)"`Astring`json:"url"validate:"isurl"`Bstring`json:"ip"validate:"isip"`}我想根据类型验证A和B,如果type=A那么A必须存在并且必须是一个URLBUT不能存在如果type=B那么A一定不存在并且B必须是一个IP验证器可以吗?我确实尝试过自定义验证,但我找不到查看

curl - Beego 如何访问使用 multipart/form-data header 提交的参数?

我遇到了如下问题:当我向我的beego应用程序发出curl请求时curlhttp://localhost:8080/controller/path-XPOST-H'Content-Type:multipart/form-data;charset=UTF-8'-F“file=@file.csv;filename=file.csv”-F“name=first”我想从我的Controller访问name参数,但是当我尝试时func(c*Controller)Path(){...varnamestringc.Ctx.Input.Bind(&name,"name")//orI'vetried'n

json - 从 golang Post Form 获取动态数组

我目前在Golang工作,我正在开发一个API,在一个POST处理程序中,我需要在Post表单中接收一个数组,但具有命名位置,我的意思是,像这样:myarray[a]:"someValue"myarray[otherName]:"someOthervalue"myarray[x]:"somethingdifferent"现在我正在尝试在CLI中使用curl发出Post请求。我要发送这个:curl-i-XPOST--urlhttp://localhost:20000/myendpoint-H"Content-Type:application/x-www-form-urlencoded"-