mirror of
https://github.com/datarhei/core.git
synced 2025-10-06 16:37:04 +08:00
Update dependencies
This commit is contained in:
2
vendor/github.com/go-playground/validator/v10/Makefile
generated
vendored
2
vendor/github.com/go-playground/validator/v10/Makefile
generated
vendored
@@ -13,6 +13,6 @@ test:
|
||||
$(GOCMD) test -cover -race ./...
|
||||
|
||||
bench:
|
||||
$(GOCMD) test -bench=. -benchmem ./...
|
||||
$(GOCMD) test -run=NONE -bench=. -benchmem ./...
|
||||
|
||||
.PHONY: test lint linters-install
|
137
vendor/github.com/go-playground/validator/v10/README.md
generated
vendored
137
vendor/github.com/go-playground/validator/v10/README.md
generated
vendored
@@ -1,7 +1,7 @@
|
||||
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://coveralls.io/github/go-playground/validator?branch=master)
|
||||
[](https://goreportcard.com/report/github.com/go-playground/validator)
|
||||
@@ -67,6 +67,12 @@ Please see https://pkg.go.dev/github.com/go-playground/validator/v10 for detaile
|
||||
Baked-in Validations
|
||||
------
|
||||
|
||||
### Special Notes:
|
||||
- If new to using validator it is highly recommended to initialize it using the `WithRequiredStructEnabled` option which is opt-in to new behaviour that will become the default behaviour in v11+. See documentation for more details.
|
||||
```go
|
||||
validate := validator.New(validator.WithRequiredStructEnabled())
|
||||
```
|
||||
|
||||
### Fields:
|
||||
|
||||
| Tag | Description |
|
||||
@@ -260,71 +266,72 @@ Benchmarks
|
||||
------
|
||||
###### Run on MacBook Pro (15-inch, 2017) go version go1.10.2 darwin/amd64
|
||||
```go
|
||||
go version go1.21.0 darwin/arm64
|
||||
goos: darwin
|
||||
goarch: amd64
|
||||
pkg: github.com/go-playground/validator
|
||||
BenchmarkFieldSuccess-8 20000000 83.6 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkFieldSuccessParallel-8 50000000 26.8 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkFieldFailure-8 5000000 291 ns/op 208 B/op 4 allocs/op
|
||||
BenchmarkFieldFailureParallel-8 20000000 107 ns/op 208 B/op 4 allocs/op
|
||||
BenchmarkFieldArrayDiveSuccess-8 2000000 623 ns/op 201 B/op 11 allocs/op
|
||||
BenchmarkFieldArrayDiveSuccessParallel-8 10000000 237 ns/op 201 B/op 11 allocs/op
|
||||
BenchmarkFieldArrayDiveFailure-8 2000000 859 ns/op 412 B/op 16 allocs/op
|
||||
BenchmarkFieldArrayDiveFailureParallel-8 5000000 335 ns/op 413 B/op 16 allocs/op
|
||||
BenchmarkFieldMapDiveSuccess-8 1000000 1292 ns/op 432 B/op 18 allocs/op
|
||||
BenchmarkFieldMapDiveSuccessParallel-8 3000000 467 ns/op 432 B/op 18 allocs/op
|
||||
BenchmarkFieldMapDiveFailure-8 1000000 1082 ns/op 512 B/op 16 allocs/op
|
||||
BenchmarkFieldMapDiveFailureParallel-8 5000000 425 ns/op 512 B/op 16 allocs/op
|
||||
BenchmarkFieldMapDiveWithKeysSuccess-8 1000000 1539 ns/op 480 B/op 21 allocs/op
|
||||
BenchmarkFieldMapDiveWithKeysSuccessParallel-8 3000000 613 ns/op 480 B/op 21 allocs/op
|
||||
BenchmarkFieldMapDiveWithKeysFailure-8 1000000 1413 ns/op 721 B/op 21 allocs/op
|
||||
BenchmarkFieldMapDiveWithKeysFailureParallel-8 3000000 575 ns/op 721 B/op 21 allocs/op
|
||||
BenchmarkFieldCustomTypeSuccess-8 10000000 216 ns/op 32 B/op 2 allocs/op
|
||||
BenchmarkFieldCustomTypeSuccessParallel-8 20000000 82.2 ns/op 32 B/op 2 allocs/op
|
||||
BenchmarkFieldCustomTypeFailure-8 5000000 274 ns/op 208 B/op 4 allocs/op
|
||||
BenchmarkFieldCustomTypeFailureParallel-8 20000000 116 ns/op 208 B/op 4 allocs/op
|
||||
BenchmarkFieldOrTagSuccess-8 2000000 740 ns/op 16 B/op 1 allocs/op
|
||||
BenchmarkFieldOrTagSuccessParallel-8 3000000 474 ns/op 16 B/op 1 allocs/op
|
||||
BenchmarkFieldOrTagFailure-8 3000000 471 ns/op 224 B/op 5 allocs/op
|
||||
BenchmarkFieldOrTagFailureParallel-8 3000000 414 ns/op 224 B/op 5 allocs/op
|
||||
BenchmarkStructLevelValidationSuccess-8 10000000 213 ns/op 32 B/op 2 allocs/op
|
||||
BenchmarkStructLevelValidationSuccessParallel-8 20000000 91.8 ns/op 32 B/op 2 allocs/op
|
||||
BenchmarkStructLevelValidationFailure-8 3000000 473 ns/op 304 B/op 8 allocs/op
|
||||
BenchmarkStructLevelValidationFailureParallel-8 10000000 234 ns/op 304 B/op 8 allocs/op
|
||||
BenchmarkStructSimpleCustomTypeSuccess-8 5000000 385 ns/op 32 B/op 2 allocs/op
|
||||
BenchmarkStructSimpleCustomTypeSuccessParallel-8 10000000 161 ns/op 32 B/op 2 allocs/op
|
||||
BenchmarkStructSimpleCustomTypeFailure-8 2000000 640 ns/op 424 B/op 9 allocs/op
|
||||
BenchmarkStructSimpleCustomTypeFailureParallel-8 5000000 318 ns/op 440 B/op 10 allocs/op
|
||||
BenchmarkStructFilteredSuccess-8 2000000 597 ns/op 288 B/op 9 allocs/op
|
||||
BenchmarkStructFilteredSuccessParallel-8 10000000 266 ns/op 288 B/op 9 allocs/op
|
||||
BenchmarkStructFilteredFailure-8 3000000 454 ns/op 256 B/op 7 allocs/op
|
||||
BenchmarkStructFilteredFailureParallel-8 10000000 214 ns/op 256 B/op 7 allocs/op
|
||||
BenchmarkStructPartialSuccess-8 3000000 502 ns/op 256 B/op 6 allocs/op
|
||||
BenchmarkStructPartialSuccessParallel-8 10000000 225 ns/op 256 B/op 6 allocs/op
|
||||
BenchmarkStructPartialFailure-8 2000000 702 ns/op 480 B/op 11 allocs/op
|
||||
BenchmarkStructPartialFailureParallel-8 5000000 329 ns/op 480 B/op 11 allocs/op
|
||||
BenchmarkStructExceptSuccess-8 2000000 793 ns/op 496 B/op 12 allocs/op
|
||||
BenchmarkStructExceptSuccessParallel-8 10000000 193 ns/op 240 B/op 5 allocs/op
|
||||
BenchmarkStructExceptFailure-8 2000000 639 ns/op 464 B/op 10 allocs/op
|
||||
BenchmarkStructExceptFailureParallel-8 5000000 300 ns/op 464 B/op 10 allocs/op
|
||||
BenchmarkStructSimpleCrossFieldSuccess-8 3000000 417 ns/op 72 B/op 3 allocs/op
|
||||
BenchmarkStructSimpleCrossFieldSuccessParallel-8 10000000 163 ns/op 72 B/op 3 allocs/op
|
||||
BenchmarkStructSimpleCrossFieldFailure-8 2000000 645 ns/op 304 B/op 8 allocs/op
|
||||
BenchmarkStructSimpleCrossFieldFailureParallel-8 5000000 285 ns/op 304 B/op 8 allocs/op
|
||||
BenchmarkStructSimpleCrossStructCrossFieldSuccess-8 3000000 588 ns/op 80 B/op 4 allocs/op
|
||||
BenchmarkStructSimpleCrossStructCrossFieldSuccessParallel-8 10000000 221 ns/op 80 B/op 4 allocs/op
|
||||
BenchmarkStructSimpleCrossStructCrossFieldFailure-8 2000000 868 ns/op 320 B/op 9 allocs/op
|
||||
BenchmarkStructSimpleCrossStructCrossFieldFailureParallel-8 5000000 337 ns/op 320 B/op 9 allocs/op
|
||||
BenchmarkStructSimpleSuccess-8 5000000 260 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkStructSimpleSuccessParallel-8 20000000 90.6 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkStructSimpleFailure-8 2000000 619 ns/op 424 B/op 9 allocs/op
|
||||
BenchmarkStructSimpleFailureParallel-8 5000000 296 ns/op 424 B/op 9 allocs/op
|
||||
BenchmarkStructComplexSuccess-8 1000000 1454 ns/op 128 B/op 8 allocs/op
|
||||
BenchmarkStructComplexSuccessParallel-8 3000000 579 ns/op 128 B/op 8 allocs/op
|
||||
BenchmarkStructComplexFailure-8 300000 4140 ns/op 3041 B/op 53 allocs/op
|
||||
BenchmarkStructComplexFailureParallel-8 1000000 2127 ns/op 3041 B/op 53 allocs/op
|
||||
BenchmarkOneof-8 10000000 140 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkOneofParallel-8 20000000 70.1 ns/op 0 B/op 0 allocs/op
|
||||
goarch: arm64
|
||||
pkg: github.com/go-playground/validator/v10
|
||||
BenchmarkFieldSuccess-8 33142266 35.94 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkFieldSuccessParallel-8 200816191 6.568 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkFieldFailure-8 6779707 175.1 ns/op 200 B/op 4 allocs/op
|
||||
BenchmarkFieldFailureParallel-8 11044147 108.4 ns/op 200 B/op 4 allocs/op
|
||||
BenchmarkFieldArrayDiveSuccess-8 6054232 194.4 ns/op 97 B/op 5 allocs/op
|
||||
BenchmarkFieldArrayDiveSuccessParallel-8 12523388 94.07 ns/op 97 B/op 5 allocs/op
|
||||
BenchmarkFieldArrayDiveFailure-8 3587043 334.3 ns/op 300 B/op 10 allocs/op
|
||||
BenchmarkFieldArrayDiveFailureParallel-8 5816665 200.8 ns/op 300 B/op 10 allocs/op
|
||||
BenchmarkFieldMapDiveSuccess-8 2217910 540.1 ns/op 288 B/op 14 allocs/op
|
||||
BenchmarkFieldMapDiveSuccessParallel-8 4446698 258.7 ns/op 288 B/op 14 allocs/op
|
||||
BenchmarkFieldMapDiveFailure-8 2392759 504.6 ns/op 376 B/op 13 allocs/op
|
||||
BenchmarkFieldMapDiveFailureParallel-8 4244199 286.9 ns/op 376 B/op 13 allocs/op
|
||||
BenchmarkFieldMapDiveWithKeysSuccess-8 2005857 592.1 ns/op 288 B/op 14 allocs/op
|
||||
BenchmarkFieldMapDiveWithKeysSuccessParallel-8 4400850 296.9 ns/op 288 B/op 14 allocs/op
|
||||
BenchmarkFieldMapDiveWithKeysFailure-8 1850227 643.8 ns/op 553 B/op 16 allocs/op
|
||||
BenchmarkFieldMapDiveWithKeysFailureParallel-8 3293233 375.1 ns/op 553 B/op 16 allocs/op
|
||||
BenchmarkFieldCustomTypeSuccess-8 12174412 98.25 ns/op 32 B/op 2 allocs/op
|
||||
BenchmarkFieldCustomTypeSuccessParallel-8 34389907 35.49 ns/op 32 B/op 2 allocs/op
|
||||
BenchmarkFieldCustomTypeFailure-8 7582524 156.6 ns/op 184 B/op 3 allocs/op
|
||||
BenchmarkFieldCustomTypeFailureParallel-8 13019902 92.79 ns/op 184 B/op 3 allocs/op
|
||||
BenchmarkFieldOrTagSuccess-8 3427260 349.4 ns/op 16 B/op 1 allocs/op
|
||||
BenchmarkFieldOrTagSuccessParallel-8 15144128 81.25 ns/op 16 B/op 1 allocs/op
|
||||
BenchmarkFieldOrTagFailure-8 5913546 201.9 ns/op 216 B/op 5 allocs/op
|
||||
BenchmarkFieldOrTagFailureParallel-8 9810212 113.7 ns/op 216 B/op 5 allocs/op
|
||||
BenchmarkStructLevelValidationSuccess-8 13456327 87.66 ns/op 16 B/op 1 allocs/op
|
||||
BenchmarkStructLevelValidationSuccessParallel-8 41818888 27.77 ns/op 16 B/op 1 allocs/op
|
||||
BenchmarkStructLevelValidationFailure-8 4166284 272.6 ns/op 264 B/op 7 allocs/op
|
||||
BenchmarkStructLevelValidationFailureParallel-8 7594581 152.1 ns/op 264 B/op 7 allocs/op
|
||||
BenchmarkStructSimpleCustomTypeSuccess-8 6508082 182.6 ns/op 32 B/op 2 allocs/op
|
||||
BenchmarkStructSimpleCustomTypeSuccessParallel-8 23078605 54.78 ns/op 32 B/op 2 allocs/op
|
||||
BenchmarkStructSimpleCustomTypeFailure-8 3118352 381.0 ns/op 416 B/op 9 allocs/op
|
||||
BenchmarkStructSimpleCustomTypeFailureParallel-8 5300738 224.1 ns/op 432 B/op 10 allocs/op
|
||||
BenchmarkStructFilteredSuccess-8 4761807 251.1 ns/op 216 B/op 5 allocs/op
|
||||
BenchmarkStructFilteredSuccessParallel-8 8792598 128.6 ns/op 216 B/op 5 allocs/op
|
||||
BenchmarkStructFilteredFailure-8 5202573 232.1 ns/op 216 B/op 5 allocs/op
|
||||
BenchmarkStructFilteredFailureParallel-8 9591267 121.4 ns/op 216 B/op 5 allocs/op
|
||||
BenchmarkStructPartialSuccess-8 5188512 231.6 ns/op 224 B/op 4 allocs/op
|
||||
BenchmarkStructPartialSuccessParallel-8 9179776 123.1 ns/op 224 B/op 4 allocs/op
|
||||
BenchmarkStructPartialFailure-8 3071212 392.5 ns/op 440 B/op 9 allocs/op
|
||||
BenchmarkStructPartialFailureParallel-8 5344261 223.7 ns/op 440 B/op 9 allocs/op
|
||||
BenchmarkStructExceptSuccess-8 3184230 375.0 ns/op 424 B/op 8 allocs/op
|
||||
BenchmarkStructExceptSuccessParallel-8 10090130 108.9 ns/op 208 B/op 3 allocs/op
|
||||
BenchmarkStructExceptFailure-8 3347226 357.7 ns/op 424 B/op 8 allocs/op
|
||||
BenchmarkStructExceptFailureParallel-8 5654923 209.5 ns/op 424 B/op 8 allocs/op
|
||||
BenchmarkStructSimpleCrossFieldSuccess-8 5232265 229.1 ns/op 56 B/op 3 allocs/op
|
||||
BenchmarkStructSimpleCrossFieldSuccessParallel-8 17436674 64.75 ns/op 56 B/op 3 allocs/op
|
||||
BenchmarkStructSimpleCrossFieldFailure-8 3128613 383.6 ns/op 272 B/op 8 allocs/op
|
||||
BenchmarkStructSimpleCrossFieldFailureParallel-8 6994113 168.8 ns/op 272 B/op 8 allocs/op
|
||||
BenchmarkStructSimpleCrossStructCrossFieldSuccess-8 3506487 340.9 ns/op 64 B/op 4 allocs/op
|
||||
BenchmarkStructSimpleCrossStructCrossFieldSuccessParallel-8 13431300 91.77 ns/op 64 B/op 4 allocs/op
|
||||
BenchmarkStructSimpleCrossStructCrossFieldFailure-8 2410566 500.9 ns/op 288 B/op 9 allocs/op
|
||||
BenchmarkStructSimpleCrossStructCrossFieldFailureParallel-8 6344510 188.2 ns/op 288 B/op 9 allocs/op
|
||||
BenchmarkStructSimpleSuccess-8 8922726 133.8 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkStructSimpleSuccessParallel-8 55291153 23.63 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkStructSimpleFailure-8 3171553 378.4 ns/op 416 B/op 9 allocs/op
|
||||
BenchmarkStructSimpleFailureParallel-8 5571692 212.0 ns/op 416 B/op 9 allocs/op
|
||||
BenchmarkStructComplexSuccess-8 1683750 714.5 ns/op 224 B/op 5 allocs/op
|
||||
BenchmarkStructComplexSuccessParallel-8 4578046 257.0 ns/op 224 B/op 5 allocs/op
|
||||
BenchmarkStructComplexFailure-8 481585 2547 ns/op 3041 B/op 48 allocs/op
|
||||
BenchmarkStructComplexFailureParallel-8 965764 1577 ns/op 3040 B/op 48 allocs/op
|
||||
BenchmarkOneof-8 17380881 68.50 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkOneofParallel-8 8084733 153.5 ns/op 0 B/op 0 allocs/op
|
||||
```
|
||||
|
||||
Complementary Software
|
||||
|
64
vendor/github.com/go-playground/validator/v10/baked_in.go
generated
vendored
64
vendor/github.com/go-playground/validator/v10/baked_in.go
generated
vendored
@@ -23,7 +23,7 @@ import (
|
||||
"golang.org/x/text/language"
|
||||
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
"github.com/leodido/go-urn"
|
||||
urn "github.com/leodido/go-urn"
|
||||
)
|
||||
|
||||
// Func accepts a FieldLevel interface for all validation needs. The return
|
||||
@@ -1295,8 +1295,13 @@ func isEq(fl FieldLevel) bool {
|
||||
|
||||
return field.Uint() == p
|
||||
|
||||
case reflect.Float32, reflect.Float64:
|
||||
p := asFloat(param)
|
||||
case reflect.Float32:
|
||||
p := asFloat32(param)
|
||||
|
||||
return field.Float() == p
|
||||
|
||||
case reflect.Float64:
|
||||
p := asFloat64(param)
|
||||
|
||||
return field.Float() == p
|
||||
|
||||
@@ -1760,8 +1765,11 @@ func requireCheckFieldValue(
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
return field.Uint() == asUint(value)
|
||||
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return field.Float() == asFloat(value)
|
||||
case reflect.Float32:
|
||||
return field.Float() == asFloat32(value)
|
||||
|
||||
case reflect.Float64:
|
||||
return field.Float() == asFloat64(value)
|
||||
|
||||
case reflect.Slice, reflect.Map, reflect.Array:
|
||||
return int64(field.Len()) == asInt(value)
|
||||
@@ -2060,8 +2068,13 @@ func isGte(fl FieldLevel) bool {
|
||||
|
||||
return field.Uint() >= p
|
||||
|
||||
case reflect.Float32, reflect.Float64:
|
||||
p := asFloat(param)
|
||||
case reflect.Float32:
|
||||
p := asFloat32(param)
|
||||
|
||||
return field.Float() >= p
|
||||
|
||||
case reflect.Float64:
|
||||
p := asFloat64(param)
|
||||
|
||||
return field.Float() >= p
|
||||
|
||||
@@ -2106,10 +2119,16 @@ func isGt(fl FieldLevel) bool {
|
||||
|
||||
return field.Uint() > p
|
||||
|
||||
case reflect.Float32, reflect.Float64:
|
||||
p := asFloat(param)
|
||||
case reflect.Float32:
|
||||
p := asFloat32(param)
|
||||
|
||||
return field.Float() > p
|
||||
|
||||
case reflect.Float64:
|
||||
p := asFloat64(param)
|
||||
|
||||
return field.Float() > p
|
||||
|
||||
case reflect.Struct:
|
||||
|
||||
if field.Type().ConvertibleTo(timeType) {
|
||||
@@ -2148,8 +2167,13 @@ func hasLengthOf(fl FieldLevel) bool {
|
||||
|
||||
return field.Uint() == p
|
||||
|
||||
case reflect.Float32, reflect.Float64:
|
||||
p := asFloat(param)
|
||||
case reflect.Float32:
|
||||
p := asFloat32(param)
|
||||
|
||||
return field.Float() == p
|
||||
|
||||
case reflect.Float64:
|
||||
p := asFloat64(param)
|
||||
|
||||
return field.Float() == p
|
||||
}
|
||||
@@ -2281,8 +2305,13 @@ func isLte(fl FieldLevel) bool {
|
||||
|
||||
return field.Uint() <= p
|
||||
|
||||
case reflect.Float32, reflect.Float64:
|
||||
p := asFloat(param)
|
||||
case reflect.Float32:
|
||||
p := asFloat32(param)
|
||||
|
||||
return field.Float() <= p
|
||||
|
||||
case reflect.Float64:
|
||||
p := asFloat64(param)
|
||||
|
||||
return field.Float() <= p
|
||||
|
||||
@@ -2327,8 +2356,13 @@ func isLt(fl FieldLevel) bool {
|
||||
|
||||
return field.Uint() < p
|
||||
|
||||
case reflect.Float32, reflect.Float64:
|
||||
p := asFloat(param)
|
||||
case reflect.Float32:
|
||||
p := asFloat32(param)
|
||||
|
||||
return field.Float() < p
|
||||
|
||||
case reflect.Float64:
|
||||
p := asFloat64(param)
|
||||
|
||||
return field.Float() < p
|
||||
|
||||
|
21
vendor/github.com/go-playground/validator/v10/cache.go
generated
vendored
21
vendor/github.com/go-playground/validator/v10/cache.go
generated
vendored
@@ -20,7 +20,6 @@ const (
|
||||
typeOr
|
||||
typeKeys
|
||||
typeEndKeys
|
||||
typeNestedStructLevel
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -153,7 +152,7 @@ func (v *Validate) extractStructCache(current reflect.Value, sName string) *cStr
|
||||
// and so only struct level caching can be used instead of combined with Field tag caching
|
||||
|
||||
if len(tag) > 0 {
|
||||
ctag, _ = v.parseFieldTagsRecursive(tag, fld, "", false)
|
||||
ctag, _ = v.parseFieldTagsRecursive(tag, fld.Name, "", false)
|
||||
} else {
|
||||
// even if field doesn't have validations need cTag for traversing to potential inner/nested
|
||||
// elements of the field.
|
||||
@@ -172,7 +171,7 @@ func (v *Validate) extractStructCache(current reflect.Value, sName string) *cStr
|
||||
return cs
|
||||
}
|
||||
|
||||
func (v *Validate) parseFieldTagsRecursive(tag string, field reflect.StructField, alias string, hasAlias bool) (firstCtag *cTag, current *cTag) {
|
||||
func (v *Validate) parseFieldTagsRecursive(tag string, fieldName string, alias string, hasAlias bool) (firstCtag *cTag, current *cTag) {
|
||||
var t string
|
||||
noAlias := len(alias) == 0
|
||||
tags := strings.Split(tag, tagSeparator)
|
||||
@@ -186,9 +185,9 @@ func (v *Validate) parseFieldTagsRecursive(tag string, field reflect.StructField
|
||||
// check map for alias and process new tags, otherwise process as usual
|
||||
if tagsVal, found := v.aliases[t]; found {
|
||||
if i == 0 {
|
||||
firstCtag, current = v.parseFieldTagsRecursive(tagsVal, field, t, true)
|
||||
firstCtag, current = v.parseFieldTagsRecursive(tagsVal, fieldName, t, true)
|
||||
} else {
|
||||
next, curr := v.parseFieldTagsRecursive(tagsVal, field, t, true)
|
||||
next, curr := v.parseFieldTagsRecursive(tagsVal, fieldName, t, true)
|
||||
current.next, current = next, curr
|
||||
|
||||
}
|
||||
@@ -236,7 +235,7 @@ func (v *Validate) parseFieldTagsRecursive(tag string, field reflect.StructField
|
||||
}
|
||||
}
|
||||
|
||||
current.keys, _ = v.parseFieldTagsRecursive(string(b[:len(b)-1]), field, "", false)
|
||||
current.keys, _ = v.parseFieldTagsRecursive(string(b[:len(b)-1]), fieldName, "", false)
|
||||
continue
|
||||
|
||||
case endKeysTag:
|
||||
@@ -285,18 +284,14 @@ func (v *Validate) parseFieldTagsRecursive(tag string, field reflect.StructField
|
||||
|
||||
current.tag = vals[0]
|
||||
if len(current.tag) == 0 {
|
||||
panic(strings.TrimSpace(fmt.Sprintf(invalidValidation, field.Name)))
|
||||
panic(strings.TrimSpace(fmt.Sprintf(invalidValidation, fieldName)))
|
||||
}
|
||||
|
||||
if wrapper, ok := v.validations[current.tag]; ok {
|
||||
current.fn = wrapper.fn
|
||||
current.runValidationWhenNil = wrapper.runValidatinOnNil
|
||||
} else {
|
||||
panic(strings.TrimSpace(fmt.Sprintf(undefinedValidation, current.tag, field.Name)))
|
||||
}
|
||||
|
||||
if current.typeof == typeDefault && isNestedStructOrStructPtr(field) {
|
||||
current.typeof = typeNestedStructLevel
|
||||
panic(strings.TrimSpace(fmt.Sprintf(undefinedValidation, current.tag, fieldName)))
|
||||
}
|
||||
|
||||
if len(orVals) > 1 {
|
||||
@@ -324,7 +319,7 @@ func (v *Validate) fetchCacheTag(tag string) *cTag {
|
||||
// isn't parsed again.
|
||||
ctag, found = v.tagCache.Get(tag)
|
||||
if !found {
|
||||
ctag, _ = v.parseFieldTagsRecursive(tag, reflect.StructField{}, "", false)
|
||||
ctag, _ = v.parseFieldTagsRecursive(tag, "", "", false)
|
||||
v.tagCache.Set(tag, ctag)
|
||||
}
|
||||
}
|
||||
|
2
vendor/github.com/go-playground/validator/v10/doc.go
generated
vendored
2
vendor/github.com/go-playground/validator/v10/doc.go
generated
vendored
@@ -247,7 +247,7 @@ Example #2
|
||||
This validates that the value is not the data types default zero value.
|
||||
For numbers ensures value is not zero. For strings ensures value is
|
||||
not "". For slices, maps, pointers, interfaces, channels and functions
|
||||
ensures the value is not nil. For structs ensures value is not the zero value.
|
||||
ensures the value is not nil. For structs ensures value is not the zero value when using WithRequiredStructEnabled.
|
||||
|
||||
Usage: required
|
||||
|
||||
|
16
vendor/github.com/go-playground/validator/v10/options.go
generated
vendored
Normal file
16
vendor/github.com/go-playground/validator/v10/options.go
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
package validator
|
||||
|
||||
// Option represents a configurations option to be applied to validator during initialization.
|
||||
type Option func(*Validate)
|
||||
|
||||
// WithRequiredStructEnabled enables required tag on non-pointer structs to be applied instead of ignored.
|
||||
//
|
||||
// This was made opt-in behaviour in order to maintain backward compatibility with the behaviour previous
|
||||
// to being able to apply struct level validations on struct fields directly.
|
||||
//
|
||||
// It is recommended you enabled this as it will be the default behaviour in v11+
|
||||
func WithRequiredStructEnabled() Option {
|
||||
return func(v *Validate) {
|
||||
v.requiredStructEnabled = true
|
||||
}
|
||||
}
|
20
vendor/github.com/go-playground/validator/v10/util.go
generated
vendored
20
vendor/github.com/go-playground/validator/v10/util.go
generated
vendored
@@ -261,13 +261,19 @@ func asUint(param string) uint64 {
|
||||
return i
|
||||
}
|
||||
|
||||
// asFloat returns the parameter as a float64
|
||||
// asFloat64 returns the parameter as a float64
|
||||
// or panics if it can't convert
|
||||
func asFloat(param string) float64 {
|
||||
|
||||
func asFloat64(param string) float64 {
|
||||
i, err := strconv.ParseFloat(param, 64)
|
||||
panicIf(err)
|
||||
return i
|
||||
}
|
||||
|
||||
// asFloat64 returns the parameter as a float64
|
||||
// or panics if it can't convert
|
||||
func asFloat32(param string) float64 {
|
||||
i, err := strconv.ParseFloat(param, 32)
|
||||
panicIf(err)
|
||||
return i
|
||||
}
|
||||
|
||||
@@ -286,11 +292,3 @@ func panicIf(err error) {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func isNestedStructOrStructPtr(v reflect.StructField) bool {
|
||||
if v.Type == nil {
|
||||
return false
|
||||
}
|
||||
kind := v.Type.Kind()
|
||||
return kind == reflect.Struct || kind == reflect.Ptr && v.Type.Elem().Kind() == reflect.Struct
|
||||
}
|
||||
|
113
vendor/github.com/go-playground/validator/v10/validator.go
generated
vendored
113
vendor/github.com/go-playground/validator/v10/validator.go
generated
vendored
@@ -99,6 +99,8 @@ func (v *validate) traverseField(ctx context.Context, parent reflect.Value, curr
|
||||
|
||||
current, kind, v.fldIsPointer = v.extractTypeInternal(current, false)
|
||||
|
||||
var isNestedStruct bool
|
||||
|
||||
switch kind {
|
||||
case reflect.Ptr, reflect.Interface, reflect.Invalid:
|
||||
|
||||
@@ -160,86 +162,61 @@ func (v *validate) traverseField(ctx context.Context, parent reflect.Value, curr
|
||||
}
|
||||
}
|
||||
|
||||
case reflect.Struct:
|
||||
|
||||
typ = current.Type()
|
||||
|
||||
if !typ.ConvertibleTo(timeType) {
|
||||
|
||||
if ct != nil {
|
||||
|
||||
if ct.typeof == typeStructOnly {
|
||||
goto CONTINUE
|
||||
} else if ct.typeof == typeIsDefault || ct.typeof == typeNestedStructLevel {
|
||||
// set Field Level fields
|
||||
v.slflParent = parent
|
||||
v.flField = current
|
||||
v.cf = cf
|
||||
v.ct = ct
|
||||
|
||||
if !ct.fn(ctx, v) {
|
||||
v.str1 = string(append(ns, cf.altName...))
|
||||
|
||||
if v.v.hasTagNameFunc {
|
||||
v.str2 = string(append(structNs, cf.name...))
|
||||
} else {
|
||||
v.str2 = v.str1
|
||||
}
|
||||
|
||||
v.errs = append(v.errs,
|
||||
&fieldError{
|
||||
v: v.v,
|
||||
tag: ct.aliasTag,
|
||||
actualTag: ct.tag,
|
||||
ns: v.str1,
|
||||
structNs: v.str2,
|
||||
fieldLen: uint8(len(cf.altName)),
|
||||
structfieldLen: uint8(len(cf.name)),
|
||||
value: current.Interface(),
|
||||
param: ct.param,
|
||||
kind: kind,
|
||||
typ: typ,
|
||||
},
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
ct = ct.next
|
||||
}
|
||||
|
||||
if ct != nil && ct.typeof == typeNoStructLevel {
|
||||
return
|
||||
}
|
||||
|
||||
CONTINUE:
|
||||
// if len == 0 then validating using 'Var' or 'VarWithValue'
|
||||
// Var - doesn't make much sense to do it that way, should call 'Struct', but no harm...
|
||||
// VarWithField - this allows for validating against each field within the struct against a specific value
|
||||
// pretty handy in certain situations
|
||||
if len(cf.name) > 0 {
|
||||
ns = append(append(ns, cf.altName...), '.')
|
||||
structNs = append(append(structNs, cf.name...), '.')
|
||||
}
|
||||
|
||||
v.validateStruct(ctx, parent, current, typ, ns, structNs, ct)
|
||||
if kind == reflect.Invalid {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if ct == nil || !ct.hasTag {
|
||||
return
|
||||
case reflect.Struct:
|
||||
isNestedStruct = !current.Type().ConvertibleTo(timeType)
|
||||
// For backward compatibility before struct level validation tags were supported
|
||||
// as there were a number of projects relying on `required` not failing on non-pointer
|
||||
// structs. Since it's basically nonsensical to use `required` with a non-pointer struct
|
||||
// are explicitly skipping the required validation for it. This WILL be removed in the
|
||||
// next major version.
|
||||
if !v.v.requiredStructEnabled && ct != nil && ct.tag == requiredTag {
|
||||
ct = ct.next
|
||||
}
|
||||
}
|
||||
|
||||
typ = current.Type()
|
||||
|
||||
OUTER:
|
||||
for {
|
||||
if ct == nil {
|
||||
if ct == nil || !ct.hasTag || (isNestedStruct && len(cf.name) == 0) {
|
||||
// isNestedStruct check here
|
||||
if isNestedStruct {
|
||||
// if len == 0 then validating using 'Var' or 'VarWithValue'
|
||||
// Var - doesn't make much sense to do it that way, should call 'Struct', but no harm...
|
||||
// VarWithField - this allows for validating against each field within the struct against a specific value
|
||||
// pretty handy in certain situations
|
||||
if len(cf.name) > 0 {
|
||||
ns = append(append(ns, cf.altName...), '.')
|
||||
structNs = append(append(structNs, cf.name...), '.')
|
||||
}
|
||||
|
||||
v.validateStruct(ctx, parent, current, typ, ns, structNs, ct)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
switch ct.typeof {
|
||||
case typeNoStructLevel:
|
||||
return
|
||||
|
||||
case typeStructOnly:
|
||||
if isNestedStruct {
|
||||
// if len == 0 then validating using 'Var' or 'VarWithValue'
|
||||
// Var - doesn't make much sense to do it that way, should call 'Struct', but no harm...
|
||||
// VarWithField - this allows for validating against each field within the struct against a specific value
|
||||
// pretty handy in certain situations
|
||||
if len(cf.name) > 0 {
|
||||
ns = append(append(ns, cf.altName...), '.')
|
||||
structNs = append(append(structNs, cf.name...), '.')
|
||||
}
|
||||
|
||||
v.validateStruct(ctx, parent, current, typ, ns, structNs, ct)
|
||||
}
|
||||
return
|
||||
|
||||
case typeOmitEmpty:
|
||||
|
||||
@@ -366,7 +343,7 @@ OUTER:
|
||||
ct = ct.next
|
||||
|
||||
if ct == nil {
|
||||
return
|
||||
continue OUTER
|
||||
}
|
||||
|
||||
if ct.typeof != typeOr {
|
||||
|
32
vendor/github.com/go-playground/validator/v10/validator_instance.go
generated
vendored
32
vendor/github.com/go-playground/validator/v10/validator_instance.go
generated
vendored
@@ -79,19 +79,20 @@ type internalValidationFuncWrapper struct {
|
||||
|
||||
// Validate contains the validator settings and cache
|
||||
type Validate struct {
|
||||
tagName string
|
||||
pool *sync.Pool
|
||||
hasCustomFuncs bool
|
||||
hasTagNameFunc bool
|
||||
tagNameFunc TagNameFunc
|
||||
structLevelFuncs map[reflect.Type]StructLevelFuncCtx
|
||||
customFuncs map[reflect.Type]CustomTypeFunc
|
||||
aliases map[string]string
|
||||
validations map[string]internalValidationFuncWrapper
|
||||
transTagFunc map[ut.Translator]map[string]TranslationFunc // map[<locale>]map[<tag>]TranslationFunc
|
||||
rules map[reflect.Type]map[string]string
|
||||
tagCache *tagCache
|
||||
structCache *structCache
|
||||
tagName string
|
||||
pool *sync.Pool
|
||||
tagNameFunc TagNameFunc
|
||||
structLevelFuncs map[reflect.Type]StructLevelFuncCtx
|
||||
customFuncs map[reflect.Type]CustomTypeFunc
|
||||
aliases map[string]string
|
||||
validations map[string]internalValidationFuncWrapper
|
||||
transTagFunc map[ut.Translator]map[string]TranslationFunc // map[<locale>]map[<tag>]TranslationFunc
|
||||
rules map[reflect.Type]map[string]string
|
||||
tagCache *tagCache
|
||||
structCache *structCache
|
||||
hasCustomFuncs bool
|
||||
hasTagNameFunc bool
|
||||
requiredStructEnabled bool
|
||||
}
|
||||
|
||||
// New returns a new instance of 'validate' with sane defaults.
|
||||
@@ -99,7 +100,7 @@ type Validate struct {
|
||||
// It caches information about your struct and validations,
|
||||
// in essence only parsing your validation tags once per struct type.
|
||||
// Using multiple instances neglects the benefit of caching.
|
||||
func New() *Validate {
|
||||
func New(options ...Option) *Validate {
|
||||
|
||||
tc := new(tagCache)
|
||||
tc.m.Store(make(map[string]*cTag))
|
||||
@@ -146,6 +147,9 @@ func New() *Validate {
|
||||
},
|
||||
}
|
||||
|
||||
for _, o := range options {
|
||||
o(v)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user