Merged in feature/semver (pull request #93)
Add semantic versioning to all services * working * Merge branch 'main' of bitbucket.org:aarete/query-orchestration into feature/semver * 1.24 mod * go upgrade * tool * Merge branch 'main' of bitbucket.org:aarete/query-orchestration into feature/semver
This commit is contained in:
+2
-2
@@ -1,8 +1,8 @@
|
||||
Package validator
|
||||
=================
|
||||
<img align="right" src="logo.png">[](https://gitter.im/go-playground/validator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||

|
||||
[](https://travis-ci.org/go-playground/validator)
|
||||

|
||||
[](https://github.com/go-playground/validator/actions)
|
||||
[](https://coveralls.io/github/go-playground/validator?branch=master)
|
||||
[](https://goreportcard.com/report/github.com/go-playground/validator)
|
||||
[](https://pkg.go.dev/github.com/go-playground/validator/v10)
|
||||
|
||||
+16
@@ -50,6 +50,7 @@ var (
|
||||
keysTag: {},
|
||||
endKeysTag: {},
|
||||
structOnlyTag: {},
|
||||
omitzero: {},
|
||||
omitempty: {},
|
||||
omitnil: {},
|
||||
skipValidationTag: {},
|
||||
@@ -1417,6 +1418,7 @@ func isPostcodeByIso3166Alpha2Field(fl FieldLevel) bool {
|
||||
panic(fmt.Sprintf("Bad field type %T", currentField.Interface()))
|
||||
}
|
||||
|
||||
postcodeRegexInit.Do(initPostcodes)
|
||||
reg, found := postCodeRegexDict[currentField.String()]
|
||||
if !found {
|
||||
return false
|
||||
@@ -1796,6 +1798,20 @@ func hasValue(fl FieldLevel) bool {
|
||||
}
|
||||
}
|
||||
|
||||
// hasNotZeroValue is the validation function for validating if the current field's value is not the zero value for its type.
|
||||
func hasNotZeroValue(fl FieldLevel) bool {
|
||||
field := fl.Field()
|
||||
switch field.Kind() {
|
||||
case reflect.Slice, reflect.Map, reflect.Ptr, reflect.Interface, reflect.Chan, reflect.Func:
|
||||
return !field.IsNil()
|
||||
default:
|
||||
if fl.(*validate).fldIsPointer && field.Interface() != nil {
|
||||
return !field.IsZero()
|
||||
}
|
||||
return field.IsValid() && !field.IsZero()
|
||||
}
|
||||
}
|
||||
|
||||
// requireCheckFieldKind is a func for check field kind
|
||||
func requireCheckFieldKind(fl FieldLevel, param string, defaultNotFoundValue bool) bool {
|
||||
field := fl.Field()
|
||||
|
||||
+5
@@ -21,6 +21,7 @@ const (
|
||||
typeKeys
|
||||
typeEndKeys
|
||||
typeOmitNil
|
||||
typeOmitZero
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -249,6 +250,10 @@ func (v *Validate) parseFieldTagsRecursive(tag string, fieldName string, alias s
|
||||
}
|
||||
return
|
||||
|
||||
case omitzero:
|
||||
current.typeof = typeOmitZero
|
||||
continue
|
||||
|
||||
case omitempty:
|
||||
current.typeof = typeOmitEmpty
|
||||
continue
|
||||
|
||||
+17
@@ -117,6 +117,10 @@ func (v *validate) traverseField(ctx context.Context, parent reflect.Value, curr
|
||||
return
|
||||
}
|
||||
|
||||
if ct.typeof == typeOmitZero {
|
||||
return
|
||||
}
|
||||
|
||||
if ct.hasTag {
|
||||
if kind == reflect.Invalid {
|
||||
v.str1 = string(append(ns, cf.altName...))
|
||||
@@ -238,6 +242,19 @@ OUTER:
|
||||
ct = ct.next
|
||||
continue
|
||||
|
||||
case typeOmitZero:
|
||||
v.slflParent = parent
|
||||
v.flField = current
|
||||
v.cf = cf
|
||||
v.ct = ct
|
||||
|
||||
if !hasNotZeroValue(v) {
|
||||
return
|
||||
}
|
||||
|
||||
ct = ct.next
|
||||
continue
|
||||
|
||||
case typeOmitNil:
|
||||
v.slflParent = parent
|
||||
v.flField = current
|
||||
|
||||
+1
@@ -21,6 +21,7 @@ const (
|
||||
tagKeySeparator = "="
|
||||
structOnlyTag = "structonly"
|
||||
noStructLevelTag = "nostructlevel"
|
||||
omitzero = "omitzero"
|
||||
omitempty = "omitempty"
|
||||
omitnil = "omitnil"
|
||||
isdefault = "isdefault"
|
||||
|
||||
Reference in New Issue
Block a user