vvalidator - 一个轻量级的 Go 参数验证器,提供 validator、is、has 三类参数验证,满足各类验证需求。采用 MIT 开源协议。
go get github.com/syyongx/vvalidator
ValidateInt(data interface{}, key string, min, max int, def ... int) (int, error) ValidateIntp(data interface{}, key string, min, max int, code int, message string, def ... int) int ValidateInt64(data interface{}, key string, min, max int64, def ... int64) (int64, error) ValidateInt64p(data interface{}, key string, min, max int64, code int, message string, def ... int64) int64 ValidateFloat(data interface{}, key string, min, max float64, def ... float64) (float64, error) ValidateFloatp(data interface{}, key string, min, max float64, code int, message string, def ... float64) float64 ValidateString(data interface{}, key string, min, max int, def ... string) (string, error) ValidateStringp(data interface{}, key string, min, max int, code int, message string, def ... string) string ValidateStringWithPattern(data interface{}, key, pattern string, def ... string) (string, error) ValidateStringWithPatternp(data interface{}, key, pattern string, code int, message string, def ... string) string ValidateEnumInt(data interface{}, key string, validValues []int, def ... int) (int, error) ValidateEnumIntp(data interface{}, key string, validValues []int, code int, message string, def ... int) int ValidateEnumInt64(data interface{}, key string, validValues []int64, def ... int64) (int64, error) ValidateEnumInt64p(data interface{}, key string, validValues []int64, code int, message string, def ... int64) int64 ValidateEnumString(data interface{}, key string, validValues []string, def ... string) (string, error) ValidateEnumStringp(data interface{}, key string, validValues []string, code int, message string, def ... string) string ValidateSlice(data interface{}, key, sep string, min, max int, def ... string) ([]string, error) ValidateSlicep(data interface{}, key, sep string, min, max int, code int, message string, def ... string) []string
IsNumeric(str string) bool IsInt(str string) bool IsFloat(str string) bool IsHexadecimal(str string) bool IsAlpha(str string) bool IsAlphanumeric(str string) bool IsIP(str string) bool IsIPv4(str string) bool IsIPv6(str string) bool IsLatitude(str string) bool IsLongitude(str string) bool IsBase64(str string) bool IsPort(str string) bool IsURL(str string) bool IsASCII(str string) bool IsPrintableASCII(str string) bool IsEmail(str string) bool IsWinPath(str string) bool IsUnixPath(str string) bool IsSemver(str string) bool IsFullWidth(str string) bool IsHalfWidth(str string) bool IsHash(str, algorithm string) bool IsMAC(str string) bool IsTime(str string, format string) bool IsRFC3339Time(str string) bool IsRFC3339WithoutZoneTime(str string) bool IsJSON(str string) bool IsUTFLetter(str string) bool IsUTFLetterNumeric(str string) bool IsHexcolor(str string) bool IsRGBcolor(str string) bool IsRGBAcolor(str string) bool IsLowerCase(str string) bool IsUpperCase(str string) bool
HasLowerCase(str string) bool HasUpperCase(str string) bool
Golang的参数校验,大多数使用的是validator(gin框架使用的是validator v8/v9)。但是,validator的缺点是,将校验的逻辑,以标签(tag)的方式写入结构体,这种方法具有很强的侵入性,并且校验逻辑不容易阅读。 为此,笔者写了checker,作为validator的替代品。checker可以替代validator, 用于结构体或非结构体的参数校验。 使用例子: ta
https://github.com/go-playground/validator 目前大都是使用validator 下面有些例子可能还会用到以下的包,请自行安装: https://github.com/go-playground/locales https://github.com/go-playground/universal-translator 1.安装 go get gopkg.in/
项目地址:https://github.com/go-playground/validator 其他中文说明文档:https://www.cnblogs.com/zj420255586/p/13542395.html 1、操作符说明 , 多操作符分割 | 或 - 跳过验证 2、常用标记说明 标记 说明 例如 required 必填 validate:“required” omitempty
go version go1.12.4 linux/amd64 源码 run 编译并运行 build 编译 clean 清除 fmt 格式化 test 测试 generate 生成源文件 vet 静态分析 模块和包 mod 模块管理 list 包查询 get 下载安装包和依赖 install 编译包和依赖 fix 更新到新API 语言系统 version 显示版本 env 显示环境变量 doc 显
安装 go get “github.com/dgrijalva/jwt-go” 登陆 // Create a new token object, specifying signing method and the claims // you would like it to contain. token := jwt.NewWithClaims(jwt.SigningMethodHS256, jw
// TestOrderPageReq 测试订单数据结构体定义 test2路由 type TestOrderPageReq struct { OpenId string `json:"open_id" binding:"required" msg:"open_id不能为空"` Page int64 `json:"page" binding:"required" msg:"page不能为空
0x00 About 接口开发中, 比较常用的操作就是对输入的参数Bean进行字段属性值校验. 在Java中, 有Annotation(注解)可以让我们方便的在的类上面添加校验信息, 那么在Go中应该如何做到这一点呢? 0x01 structTag StructType = "struct" "{" { FieldDecl ";" } "}" . FieldDecl = (IdentifierLi
Token验证是验证用户身份的重要方式,在golang开发中具有广泛应用,文中主要阐述了利用jwt包加密后的token验证。 导入包: import ( "github.com/dgrijalva/jwt-go" ) // GenerateToken 生成Token func GenerateToken(mapClaims jwt.MapClaims, key string) (string, e
package utils import ( "errors" "github.com/astaxie/beego" "github.com/dgrijalva/jwt-go" "time" ) type TokenClaims struct { jwt.StandardClaims Uid int64 `json:"uid"` Uname s
安装 go get:go get github.com/go-playground/validator/v10 import:import “github.com/go-playground/validator/v10” 一般使用方式 给结构体表上validate标签,并指明限制 新建验证器 验证字段 遍历输出错误信息 1、验证 官方文档:validate官方验证文档 标记之间特殊符号说明 逗号(
The JSON Validator http://jsonlint.com/
主要内容:使用普通函数创建 goroutine,使用匿名函数创建goroutine在编写 Socket 网络程序时,需要提前准备一个线程池为每一个 Socket 的收发包分配一个线程。开发人员需要在线程数量和 CPU 数量间建立一个对应关系,以保证每个任务能及时地被分配到 CPU 上进行处理,同时避免多个任务频繁地在线程间切换执行而损失效率。 虽然,线程池为逻辑编写者提供了线程分配的抽象机制。但是,如果面对随时随地可能发生的并发和线程处理需求,线程池就不是非常直观和方便了。能否
Jboot 从 V3.7.5 开始,增强 Jboot 的验证方式,在 Jboot 之前的 @EmptyValidate、@RegexValidate 等基础上,进一步基于 JSR 303 – Bean Validation 简化了验证方式,相比 Spring 更加优雅简单。 @NotNull 在 Controller (或 Service 等)中,我们可以直接通过 @NotNull 注解给 Con
第一节 Go语言安装与测试 轻松友好的安装方式,多平台支持。 第二节 内置基础数据类型 认识Go提供的清晰的数据类型,很清晰,不骗你。 第三节 变量与常量定义 学语言绕不开的变量,当然Go是静态语言,变量都是有固定类型的,程序运行过程中无法改变变量类型。 第四节 控制流程 很简单,只有if,for,switch三种流程,连while都没有。 第五节 数组,切片和字典 内置高级数据类型。如果我们需要
Go轻松学是一款学习GoLang的小型学习App。基于Android平台。主要包含Go基础和Go实例两部分。 Go轻松学,可以让你随时随地浏览Go提供的独特功能,本应用提供了翔实的测试例程序,100%测试通过。并且可以根据反馈持续更新。在这里,变量,函数,结构体,指针,并行计算,包和测试都有详细的讲解。 Go基础部分由本人的读书笔记归纳整理而来,而实例部分则由网址http://gobyexampl
问题内容: 我是(Golang)的新手。我的问题与这篇文章有关。runtime.Gosched到底做什么?。代码的结构如下所示。我的问题是,当我更改GOMAXPROCS中的处理器数量时,如何验证它正在运行多少个处理器。当我执行“top”操作时,即使GOMAXPROCS大于1,它也会显示a.out进程占用100%或更少的资源。对于您的帮助,我将不胜感激。 问题答案: 该过程可以在给定的时间内运行的逻
Jenkins Pipeline插件有一个称为“轻量级签出”的功能,其中主服务器仅从repo中提取Jenkinsfile,而不是整个repo。配置屏幕中有一个相应的复选框。我想在多分支管道中进行轻量级签出,但我在多分支配置屏幕中没有看到复选框。有什么想法如何实现这一点吗?我注意到一些关闭的问题表明此功能可用,但我无法找到任何有关如何实现它的细节。 相关资料: https://issues.jenk