NipGeihou's blog NipGeihou's blog
  • Java

    • 开发规范
    • 进阶笔记
    • 微服务
    • 快速开始
    • 设计模式
  • 其他

    • Golang
    • Python
    • Drat
  • Redis
  • MongoDB
  • 数据结构与算法
  • 计算机网络
  • 应用

    • Grafana
    • Prometheus
  • 容器与编排

    • KubeSphere
    • Kubernetes
    • Docker Compose
    • Docker
  • 组网

    • TailScale
    • WireGuard
  • 密码生成器
  • 英文单词生成器
🍳烹饪
🧑‍💻关于
  • 分类
  • 标签
  • 归档

NipGeihou

我见青山多妩媚,料青山见我应如是
  • Java

    • 开发规范
    • 进阶笔记
    • 微服务
    • 快速开始
    • 设计模式
  • 其他

    • Golang
    • Python
    • Drat
  • Redis
  • MongoDB
  • 数据结构与算法
  • 计算机网络
  • 应用

    • Grafana
    • Prometheus
  • 容器与编排

    • KubeSphere
    • Kubernetes
    • Docker Compose
    • Docker
  • 组网

    • TailScale
    • WireGuard
  • 密码生成器
  • 英文单词生成器
🍳烹饪
🧑‍💻关于
  • 分类
  • 标签
  • 归档
  • Java视角看Go

  • other

  • 笔记

    • go-tagexpr常用表达式
      • validator
  • 代码片段

  • Golang
  • 笔记
NipGeihou
2023-07-02
目录

go-tagexpr常用表达式

# validator

参考:https://github.com/bytedance/go-tagexpr/tree/master/validator

type InfoRequest struct {
    Name         string   `vd:"($!='Alice'||(Age)$==18) && regexp('\\w')"`
    Name2	string `vd:"@:len($)>0; msg:'Name2不能为空'"`
    Age          int      `vd:"$>0"`
    Email        string   `vd:"email($)"`
    Phone1       string   `vd:"phone($)"`
    OtherPhones  []string `vd:"range($, phone(#v,'CN'))"`
    *InfoRequest `vd:"?"`
    Info1        *InfoRequest `vd:"?"`
    Info2        *InfoRequest `vd:"-"`
}
作用 表达式 可用类型 备注
字符串必填 len($)>0 string
数值必填 $>0 number
当 A=X 时,当前字段必填 (A)$==X && len($)>0
(A)$==X && $>0
上次更新: 2023/07/03, 00:52:01
使用go-admin那些坑
导出CSV

← 使用go-admin那些坑 导出CSV→

最近更新
01
Docker Swarm
04-18
02
安全隧道 - gost
04-17
03
Solana最佳实践
04-16
更多文章>
Theme by Vdoing | Copyright © 2018-2025 NipGeihou | 友情链接
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式