GitHub is where people build software. More than 150 million people use GitHub to discover, fork, and contribute to over 420 million projects.
import "github.com/go-playground/validator" Error Return Value Validation functions return type error They return type error to avoid the issue discussed in the following, where err is always != nil: http://stackoverflow.com/a/29138676/3158232 https://github.com/go-playground/validator/issues...
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...
"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...
可见这真的是一个更好的 Playground,一定程度上有点在线编辑器的感觉。该项目在 GitHub 的地址:https://github.com/x1unix/go-playground。后记 除了以上三款,其实还有一些其他的,比较小众,因此不做对比。最后,推荐大家以后可以使用 https://goplay.tools/,有兴趣的也可以为它贡献代码。参考资料 [1]Go ...
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 ...
Name为必填字段 依然不是很友好,这个时候我们就需要自定义错误内容: 名称为必填字段 代码如下: package utils import ( CN_ZH "github.com/go-playground/locales/zh" ut "github.com/go-playground/universal-translator" "github.com/go-playground/validator/v10" ...
packagemainimport("bytes""fmt""github.com/go-playground/log/v8")// CustomHandler is your custom handlertypeCustomHandlerstruct{// whatever properties you need}// Log accepts log entries to be processedfunc(c*CustomHandler)Log(elog.Entry) {// below prints to os.Stderr but could marshal to ...
[1] 官方Go Playground 项目: github.com/golang/playg[2] 可以自取: github.com/soulteary/go[3] 下载安装文件: docker.com/get-started/[4] 更简单的 Docker 安装: soulteary.com/2022/06/2[5] 这篇官方博客: blog.go-zh.org/playgrou 如果你觉得内容还算实用,欢迎点赞分享给你的朋友,在此谢过。
先简单看看这款 Playground:gpgsync。这是 syumai 开发的一款多人协同编辑的 Go Playground,他是一个 TypeScript 和 Go 爱好者。项目地址:https://github.com/syumai/gpgsync,这是一个 Node 项目,你可以本地搭建,也可以直接试用作者提供的 Demo:https://gpgsync.herokuapp.com/。如何使用 打开 https:...