Go 结构体标签表达式 go-tagexpr

码农软件 · 软件分类 · 其他开发相关 · 2019-10-15 22:26:52

软件介绍

go-tagexpr 由字节跳动开源,实现了 Golang 结构体标签表达式解释器,可用于各种场景的请求参数校验。

主要特性:

  • 支持各种常用运算符

  • 支持访问数组、切片、字典的成员

  • 支持访问当前结构中任意字段

  • 支持访问嵌套字段、非导出字段等

  • 内置 len、sprintf、regexp 函数

  • 支持单表达式与多表达式两种定义模式

  • 提供了参数校验子包

可以看一个参数校验的小例子:

package validator_test

import (
	"fmt"

	"github.com/bytedance/go-tagexpr/validator"
)

func Example() {
	var vd = validator.New("vd")

	type InfoRequest struct {
		Name string `vd:"($!='Alice'||(Age)$==18) && regexp('\\w')"`
		Age  int    `vd:"$>0"`
	}
	info := &InfoRequest{Name: "Alice", Age: 18}
	fmt.Println(vd.Validate(info) == nil)
	// Output:
	// true
}

本文地址:https://www.codercto.com/soft/d/16846.html

Introduction to the Design and Analysis of Algorithms

Introduction to the Design and Analysis of Algorithms

Anany Levitin / Addison Wesley / 2006-2-24 / USD 122.00

Based on a Based on a new classification of algorithm design techniques and a clear delineation of analysis methods, "Introduction to the Design and Analysis of Algorithms" presents the subject in a c......一起来看看 《Introduction to the Design and Analysis of Algorithms》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具