首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏code人生

    使用 `github.com/go-playground/form/v4` 处理表单数据

    github.com/go-playground/form/v4 是一个强大而灵活的库,用于轻松地在 Go 语言中处理表单数据。本文将介绍该库的基本用法,并提供一个简单的示例。 安装首先,你需要安装 github.com/go-playground/form/v4。 使用以下命令完成安装:go get -u github.com/go-playground/form/v4示例考虑以下示例,演示了如何使用该库处理表单数据:package mainimport ("fmt 然后,我们创建了一个 User 结构体,并使用 github.com/go-playground/form/v4 解码表单数据到结构体中。 进一步探索github.com/go-playground/form/v4 还提供了许多其他功能,包括处理嵌套结构体、自定义解码器和验证等。你可以在 GitHub 仓库 上找到更多详细的文档。

    41750编辑于 2023-11-20
  • 来自专栏golang开发笔记

    golang之数据验证validator

    go-playground上提供了很好的解决方法。 先自行安装需要的两个包 https://github.com/go-playground/locales https://github.com/go-playground/universal-translator 执行: go get github.com/go-playground/universal-translator go get github.com/go-playground/locales 示例: package main import ( "fmt" "github.com/go-playground/locales/zh" ut "github.com/go-playground package main import ( "fmt" "github.com/go-playground/locales/zh" ut "github.com/go-playground

    1.9K41发布于 2020-09-27
  • 来自专栏艺述论专栏

    使用 jsMpeg + webscoket 低延迟播放直接流

    使用示例源码 链接: https://github.com/rixingyike/gin-rtsp 可能遇到问题: cannot find package "github.com/go-playground /validator/v10" 方法: 1、go get “gopkg.in/go-playground/validator.v10” 2、mkdir -p $GOPATH/src/vendor/github.com /go-playground/validator/v10 3、cp -rf $GOPATH/src/gopkg.in/go-playground/validator.v10/* $GOPATH/src/ vendor/github.com/go-playground/validator/v10 参考链接: https://www.cnblogs.com/haoxi/p/12066634.html https

    3.3K30发布于 2020-02-11
  • 来自专栏Go语言指北

    gin博客项目复盘--03错误处理、数据验证

    db.Model(&users).Count(&total) return users, total } 后端数据验证 使用 gin 框架内置包 「validator」 "github.com/go-playground validator.go package validator import ( "fmt" "ginVue3blog/utils/errmsg" //注意需要引入如下4个包 "github.com/go-playground /locales/zh_Hans_CN" //中文包 unTrans "github.com/go-playground/universal-translator" //翻译包 "github.com /go-playground/validator/v10" zhTrans "github.com/go-playground/validator/v10/translations/zh" "reflect

    57920编辑于 2022-11-07
  • 来自专栏旅途散记

    Go中最常用的数据校验库

    项目地址: github.com/go-playground/validator/v10 标记 标记说明 例 required 必填 Field或Struct validate:"required" omitempty /locales/en" "github.com/go-playground/locales/zh" ut "github.com/go-playground/universal-translator " "github.com/go-playground/validator/v10" zhtrans "github.com/go-playground/validator/v10/translations /zh" // entrans "github.com/go-playground/validator/v10/translations/en" ) /* https://www.cnblogs.com Field1 Field2字段都为空时,则当前字段不能为空 package main import ( "fmt" "github.com/go-playground/validator/v10

    75410编辑于 2024-02-26
  • 来自专栏跟着asong学Golang

    boss: 这小子还不会使用validator库进行数据校验,开了~~~

    后来在同事CR的时候,说GIN有更好的参数检验方法,gin框架使用github.com/go-playground/validator进行参数校验,我们只需要在定义结构体时使用binding或validatetag # 第一次安装使用如下命令 $ go get github.com/go-playground/validator/v10 # 项目中引入包 import "github.com/go-playground 先安装这个库: $ go get github.com/go-playground/validator/v10 然后先写一个简单的示例: package main import ( "fmt" /locales/en" "github.com/go-playground/locales/zh" ut "github.com/go-playground/universal-translator " "github.com/go-playground/validator/v10" enTranslations "github.com/go-playground/validator/v10/translations

    1K20编辑于 2022-07-07
  • 如何在Go语言中实现表单验证?整一个validator吧!

    http""reflect""strings""time""github.com/gin-gonic/gin""github.com/gin-gonic/gin/binding""github.com/go-playground /locales/en""github.com/go-playground/locales/zh"ut "github.com/go-playground/universal-translator""github.com /go-playground/validator/v10"enTranslations "github.com/go-playground/validator/v10/translations/en"zhTranslations "github.com/go-playground/validator/v10/translations/zh")// 定义一个全局翻译器var trans ut.Translator表单数据结构定义首先 // removeTopStruct 去除字段名中的结构体名称标识// refer from:https://github.com/go-playground/validator/issues/633#

    58210编辑于 2024-11-20
  • 来自专栏新亮笔记

    根据使用者反馈,对开源项目 go-gin-api 新增两个功能

    = nil { fmt.Println(validation.Error(err)) } 错误信息语言包 错误信息语言包使用的是 go-playground/validator[2] 中文:v10 参考资料 [1] go-gin-api: https://github.com/xinliangnote/go-gin-api [2] go-playground/validator: https:// github.com/go-playground/validator

    47030发布于 2021-07-20
  • 来自专栏IT综合技术分享

    常见问题之Golang——verifying github.com/go-playground/assert/v2@v2.0.1/go.mod: checksum mismatch错误

    常见问题之Golang——verifying github.com/go-playground/assert/v2@v2.0.1/go.mod: checksum mismatch错误 背景 本系列文章均为学习过程中记录的笔记 正文 错误 verifying github.com/go-playground/assert/v2@v2.0.1/go.mod: checksum mismatch downloaded

    68320编辑于 2022-01-07
  • 来自专栏福大大架构师每日一题

    2022-04-05:golang中go.mod文件,做框架开发需要解析,请问如何解析?

    github.com/gin-contrib/sse v0.1.0 // indirect github.com/gin-gonic/gin v1.7.7 // indirect github.com/go-playground /locales v0.14.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect github.com /go-playground/validator/v10 v10.10.1 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com

    31810编辑于 2022-04-05
  • 来自专栏新亮笔记

    Gin框架 - 数据绑定和验证

    validator/member/member.go package member import ( "gopkg.in/go-playground/validator.v8" "reflect validator/member" "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" "gopkg.in/go-playground 从框架源码了解到验证使用的是: gopkg.in/go-playground/validator.v8 文档地址为: https://godoc.org/gopkg.in/go-playground/validator.v8

    2K20发布于 2019-07-24
  • 来自专栏Golang语言开发栈

    Golang 语言的值验证库 Validator 怎么使用?

    安装: 使用 go get: go get github.com/go-playground/validator/v10 然后将 Validator 包导入到代码中: import "github.com /go-playground/validator/v10" 02 变量验证 Var 方法使用 tag(标记)验证方式验证单个变量。 参考资料: https://github.com/go-playground/validator

    3.5K40发布于 2021-01-08
  • 来自专栏运维开发王义杰

    Go: Gin框架中的binding验证器使用指南

    首先,我们需要安装Gin框架和validator库,可以使用以下命令进行安装: sh go get -u github.com/gin-gonic/gin go get -u github.com/go-playground /validator/v10 go-playground/validator是一个用于 Go 语言的结构体和字段验证包。 下面是一个具体的示例: go package main import ( "github.com/gin-gonic/gin" "github.com/go-playground/validator 可以通过自定义验证器实现: go package main import ( "net/http" "unicode" "github.com/gin-gonic/gin" "github.com/go-playground

    2.3K10编辑于 2024-05-31
  • 来自专栏go语言

    golang一些常用库(3)

    http.ListenAndServe(":8080", r)}24. github.com/go-playground/validator - 结构体验证器Validator 提供了用于验证结构体字段的功能 goCopy codepackage mainimport ("fmt""github.com/go-playground/validator/v10")type User struct {Name

    30410编辑于 2024-02-04
  • 来自专栏Go工具箱

    「Go框架」深入解析gin中使用validator包对请求体进行验证

    "net/http" "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" validator "github.com/go-playground validator.Validate是使用的第三方包github.com/go-playground/validator/v10。 那么 binding.Validator 对象又是什么呢? 所以,在校验函数中传入validator.StructLevel类型的变量是github.com/go-playground/validator/v10这个校验包的特性。 binding的tag是gin框架在初始化**github.com/go-playground/validator/v10**包的对象时设置的。 binding标签是github.com/go-playground/validator/v10 包中设置的tag。其属性自然是和validator包有关系。

    1.4K30编辑于 2023-08-28
  • 来自专栏加菲的博客

    【One by one系列】一步步学习Golang web框架Gin

    module github.com/carfield go 1.13 require ( github.com/gin-gonic/gin v1.5.0 // indirect github.com/go-playground reflect2 v1.0.1 // indirect golang.org/x/sys v0.0.0-20200117145432-59e60aa80a0c // indirect gopkg.in/go-playground

    35410编辑于 2022-06-23
  • 来自专栏开发技术那些事

    Go语言学习(十)| module 使用

    v0.0.6 // indirect github.com/ugorji/go/codec v0.0.0-20190309163734-c4a1c341dc93 // indirect gopkg.in/go-playground v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/go-playground /validator.v8 v8.18.2 h1:lFB4DoMU6B626w8ny76MV7VX6W2VHct2GVOI3xgiMrQ= gopkg.in/go-playground/validator.v8

    52410发布于 2020-07-21
  • 来自专栏Elixir

    Go 编程 | 连载 21 - Go Modules 和 Package

    github.com/gin-contrib/sse v0.1.0 // indirect github.com/gin-gonic/gin v1.8.1 // indirect github.com/go-playground /locales v0.14.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect github.com/go-playground/validator/v10 v10.11.0 // indirect github.com/goccy/go-json v0.9.10 // indirect

    67420编辑于 2022-09-28
  • 来自专栏奕知伴解

    Go Web开发框架基本组成

    ( "fmt" "net/http" "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" "github.com/go-playground /locales/en" "github.com/go-playground/locales/zh" ut "github.com/go-playground/universal-translator " "github.com/go-playground/validator/v10" enTranslations "github.com/go-playground/validator/v10/translations /en" zhTranslations "github.com/go-playground/validator/v10/translations/zh" ) // 定义一个全局翻译器T var trans

    1.4K10发布于 2020-12-30
  • 来自专栏jerryteng的专栏

    在golang中进行数据模型的校验

    我们在处理我们的业务逻辑的时候, 一般前端传过来的信息,后端代码一定是抱着 所有信息都不信任的态度, 所有的输入信息我们都需要进行校验, 我们在代码实践的过程中,用的xml写的idl进行数据的校验,校验的工具采用的是 go-playground 这里不详细的展开, 下面来一个使用示例: package main import ( "fmt" "github.com/go-playground/validator/v10" )

    1.5K50发布于 2021-09-06
领券