Skip to content

protoc-gen-verifier is a protoc plugin which helps generate verification method on message field.

Notifications You must be signed in to change notification settings

ryanreadbooks/protoc-gen-verifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

protoc-gen-verifier

该仓库演示了如何进行protoc插件的开发。

protoc-gen-verifier可以根据指定的校验规则对message中的字段进行校验。 获取到每个字段上面的注释,所以为了简单起见,规定校验规则需要在字段的leading comments中指定。

支持的校验标签(tag)如下表所示:

proto类型 支持的校验规则(tag) 示例
int32
int64
uint32
uint64
sint32
sint64
fixed32
fixed64
sfixed32
sfixed64
eq 数值等于
gt 数值大于
gte 数值大于等于
lt 数值小于
lte 数值小于等于
ne 数值不等于
string
len 字符串长度等于 len=11
alpha 字符串全部为字母
number 字符串表示的内容为数字
contains 字符串中包含子字符串 contains=hello|world
startswith 字符串以特定内容开头
endswith 字符串以特定内容结尾
eq 字符串相等 eq=helloworld
ne 字符串不相等
bytes
len 字节切片长度等于
ne 字节切片长度不等于
repeated修饰
len 切片长度等于
ne 切片长度不等于
map
len map中键值对数量等于
ne map中键值对数量不等于 ne=6
bool
eq 布尔值相等 eq=true或eq=false

About

protoc-gen-verifier is a protoc plugin which helps generate verification method on message field.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages