feat(validator): add notblank validation

This commit is contained in:
LinkinStar 2023-02-01 11:08:56 +08:00
parent 2395503ad8
commit ec871efc75
2 changed files with 3 additions and 1 deletions

2
go.mod
View File

@ -5,6 +5,7 @@ go 1.18
require (
github.com/Chain-Zhang/pinyin v0.1.3
github.com/anargu/gin-brotli v0.0.0-20220116052358-12bf532d5267
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/bwmarrin/snowflake v0.3.0
github.com/davecgh/go-spew v1.1.1
github.com/disintegration/imaging v1.6.2
@ -55,7 +56,6 @@ require (
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/containerd/continuity v0.3.0 // indirect

View File

@ -23,6 +23,7 @@ import (
chineseTraditional "github.com/go-playground/locales/zh_Hant_TW"
ut "github.com/go-playground/universal-translator"
"github.com/go-playground/validator/v10"
"github.com/go-playground/validator/v10/non-standard/validators"
"github.com/go-playground/validator/v10/translations/en"
"github.com/go-playground/validator/v10/translations/es"
"github.com/go-playground/validator/v10/translations/fr"
@ -99,6 +100,7 @@ func getTran(lo locales.Translator) ut.Translator {
func createDefaultValidator(la i18n.Language) *validator.Validate {
validate := validator.New()
_ = validate.RegisterValidation("notblank", validators.NotBlank)
validate.RegisterTagNameFunc(func(fld reflect.StructField) (res string) {
defer func() {
if len(res) > 0 {