GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 420 million projects.
This project has grown large enough that more than one person is required to properly support the community. If you are interested in becoming a maintainer please reach out to me https://github.com/deankarnAbout💯Go Struct and Field validation, including Cross Field, Cross Struct, Map, ...
packagemainimport("fmt""github.com/go-playground/form/v4""net/http")typeUserstruct{Usernamestring`form:"username"`Passwordstring`form:"password"`}funcmain(){// 创建一个新的表单编解码器decoder:=form.NewDecoder()// 模拟 HTTP 请求req,err:=http.NewRequest("POST","/login",nil)iferr!=nil{fmt...
可见这真的是一个更好的 Playground,一定程度上有点在线编辑器的感觉。该项目在 GitHub 的地址:https://github.com/x1unix/go-playground。后记 除了以上三款,其实还有一些其他的,比较小众,因此不做对比。最后,推荐大家以后可以使用 https://goplay.tools/,有兴趣的也可以为它贡献代码。参考资料 [1]Go Pl...
先简单看看这款 Playground:gpgsync。这是 syumai 开发的一款多人协同编辑的 Go Playground,他是一个 TypeScript 和 Go 爱好者。项目地址:https://github.com/syumai/gpgsync,这是一个 Node 项目,你可以本地搭建,也可以直接试用作者提供的 Demo:https://gpgsync.herokuapp.com/。如何使用 打开 https:...
[1]官方 Go Playground 项目:https://github.com/golang/playground [2]可以自取:https://github.com/soulteary/golang-playground [3]下载安装文件:https://www.docker.com/get-started/ [4]更简单的 Docker 安装:https://soulteary.com/2022/06/21/building-a-cost-effective-linux-learning-environment-on...
go get github.com/go-playground/validator 代码 package main import ( "fmt" "github.com/go-playground/validator" ) var validate *validator.Validate //定义 type User struct { Name string `validate:"required"` //非空 Age uint8 `validate:"gte=0,lte=130"` // 0<=Age<=130 ...
gogetgithub.com/go-playground/validator 1. 代码 packagemain import( "fmt" "github.com/go-playground/validator" ) varvalidate*validator.Validate//定义 typeUserstruct{ Namestring`validate:"required"`//非空 Ageuint8`validate:"gte=0,lte=120"`// 0<=Age<=120 ...
https://github.com/go-playground/validator/issues/134 Validator only InvalidValidationError for bad validation input, nil or ValidationErrors as type error; so, in your code all you need to do is check if the error returned is not nil, and if it's not check if error is InvalidValidationErr...
"github.com/go-playground/validator/v10" ) type Application struct { Applicants []Applicant `validate:"dive"` } type Applicant struct { ApplicantCategory string `validate:"required,oneof=PERSON ENTITY"` Person Person `validate:"required_if=ApplicantCategory PERSON"` Entity Entity `validate:"require...