Skip to content

Releases: go-playground/validator

Release 9.3.1

07 Dec 01:55

Choose a tag to compare

What was fixed?

structonly did not behave as expected when not accompanied by a struct validation thanks @thessem for reporting in #264 😄

Release 9.3.0

30 Nov 13:44

Choose a tag to compare

What was added?

  • added alphaunicode and alphanumunicode validations which are basically just unicode variants of the alpha and alphanum validations that were ASCII only.

relates to #261

Release 9.2.2

16 Nov 01:41

Choose a tag to compare

What was fixed

update cached fields to be stored in array instead of map for #260 thanks @jonmchan for reporting

  • errors now always print out in order for tests
  • performance enhancement from array vs map is nice too ;)
benchmark                                                       old ns/op     new ns/op     delta
BenchmarkFieldSuccess-8                                         101           100           -0.99%
BenchmarkFieldSuccessParallel-8                                 33.2          33.7          +1.51%
BenchmarkFieldFailure-8                                         323           332           +2.79%
BenchmarkFieldFailureParallel-8                                 112           113           +0.89%
BenchmarkFieldDiveSuccess-8                                     719           714           -0.70%
BenchmarkFieldDiveSuccessParallel-8                             230           225           -2.17%
BenchmarkFieldDiveFailure-8                                     1001          987           -1.40%
BenchmarkFieldDiveFailureParallel-8                             323           317           -1.86%
BenchmarkFieldCustomTypeSuccess-8                               263           264           +0.38%
BenchmarkFieldCustomTypeSuccessParallel-8                       82.6          81.4          -1.45%
BenchmarkFieldCustomTypeFailure-8                               327           328           +0.31%
BenchmarkFieldCustomTypeFailureParallel-8                       116           116           +0.00%
BenchmarkFieldOrTagSuccess-8                                    871           878           +0.80%
BenchmarkFieldOrTagSuccessParallel-8                            394           402           +2.03%
BenchmarkFieldOrTagFailure-8                                    568           569           +0.18%
BenchmarkFieldOrTagFailureParallel-8                            397           401           +1.01%
BenchmarkStructLevelValidationSuccess-8                         332           267           -19.58%
BenchmarkStructLevelValidationSuccessParallel-8                 105           82.4          -21.52%
BenchmarkStructLevelValidationFailure-8                         637           557           -12.56%
BenchmarkStructLevelValidationFailureParallel-8                 260           226           -13.08%
BenchmarkStructSimpleCustomTypeSuccess-8                        525           452           -13.90%
BenchmarkStructSimpleCustomTypeSuccessParallel-8                155           144           -7.10%
BenchmarkStructSimpleCustomTypeFailure-8                        828           738           -10.87%
BenchmarkStructSimpleCustomTypeFailureParallel-8                345           285           -17.39%
BenchmarkStructFilteredSuccess-8                                744           664           -10.75%
BenchmarkStructFilteredSuccessParallel-8                        274           257           -6.20%
BenchmarkStructFilteredFailure-8                                595           517           -13.11%
BenchmarkStructFilteredFailureParallel-8                        250           195           -22.00%
BenchmarkStructPartialSuccess-8                                 674           608           -9.79%
BenchmarkStructPartialSuccessParallel-8                         256           225           -12.11%
BenchmarkStructPartialFailure-8                                 928           848           -8.62%
BenchmarkStructPartialFailureParallel-8                         399           360           -9.77%
BenchmarkStructExceptSuccess-8                                  1076          934           -13.20%
BenchmarkStructExceptSuccessParallel-8                          237           200           -15.61%
BenchmarkStructExceptFailure-8                                  873           787           -9.85%
BenchmarkStructExceptFailureParallel-8                          365           333           -8.77%
BenchmarkStructSimpleCrossFieldSuccess-8                        539           489           -9.28%
BenchmarkStructSimpleCrossFieldSuccessParallel-8                201           168           -16.42%
BenchmarkStructSimpleCrossFieldFailure-8                        788           709           -10.03%
BenchmarkStructSimpleCrossFieldFailureParallel-8                322           299           -7.14%
BenchmarkStructSimpleCrossStructCrossFieldSuccess-8             795           683           -14.09%
BenchmarkStructSimpleCrossStructCrossFieldSuccessParallel-8     241           211           -12.45%
BenchmarkStructSimpleCrossStructCrossFieldFailure-8             1110          940           -15.32%
BenchmarkStructSimpleCrossStructCrossFieldFailureParallel-8     399           333           -16.54%
BenchmarkStructSimpleSuccess-8                                  367           285           -22.34%
BenchmarkStructSimpleSuccessParallel-8                          108           91.0          -15.74%
BenchmarkStructSimpleFailure-8                                  776           698           -10.05%
BenchmarkStructSimpleFailureParallel-8                          307           284           -7.49%
BenchmarkStructComplexSuccess-8                                 2224          1622          -27.07%
BenchmarkStructComplexSuccessParallel-8                         718           526           -26.74%
BenchmarkStructComplexFailure-8                                 5350          4717          -11.83%
BenchmarkStructComplexFailureParallel-8                         2097          1853          -11.64%

Release 9.2.1

28 Sep 15:03

Choose a tag to compare

What was fixed?

The required tag was not correctly validating pointer fields like the old v8 exists tag ( see issue #142 ) was and so that bug has been corrected. thanks @codepushr for reporting

  • added required tag to the restricted tags that cannot be overridden because of it's dual functionality with pointers ( thought it already was, my mistake )

Release 9.2.0

25 Sep 17:56

Choose a tag to compare

What's new?

Added StructFiltered(s interface{}, fn FilterFunc) function to allow for better filtering of fields besides StructPartial or StructExcept for #255

thanks @jawher for the idea

Release 9.1.3

22 Sep 23:09

Choose a tag to compare

What was fixed?

Explicitly qualify universal-translator imports; thanks @jawher

Release 9.1.2

19 Sep 15:37

Choose a tag to compare

What was fixed?

  • accidentally cut a release before changes were pushed, fix release for v9.1.1; apologies for the noise.

Release 9.1.1

19 Sep 15:33

Choose a tag to compare

What was fixed?

  • added missing iscolor alias translation
  • correct 2 issues with or's
    • param wasn't being set on the returned or tag eg. rgb|rgba|len=10 was missing the =10 when reporting the tag in error
    • corrected issue when tags may exist past the or's as a double check, nobody has ever run into this but I did adding some new functionality not yet released, and wanted to add it in now for the future.

Release 9.1.0

15 Sep 19:59

Choose a tag to compare

What's New?

🎉 This change has been a long time coming 🎉

The story so far....

A long time ago in a validator package on a github server far far away...

A request was made for allowing custom validations #174 but the evil i18n,

localization of errors, stood in our way #230. An expedition was dispatched to

search the vastness open source, but alas no suitable i18n package with correct

pluralization rules could be found; the outlook for validator seemed grim; until a

developer created an i18n and l10n helper package locales and an i18n package

universal-translator that wraps it and then jammed that functionality deep inside of validator!

So without further ado:

  • Added i18n aware Custom Error Message translations see here for an example
    • Custom Translation can be registered using RegisterTranslation
    • A Default set of translations exists for the en locale here; if anyone could help in adding more for other locales that would be appreciated 😄

Release 9.0.0

01 Sep 13:03

Choose a tag to compare

Release 9.0.0

After much work, tweaking and design updates validator v9 has been released!

It's even faster, more efficient and built for ease of use!

Quick overview of changes

documentation has been updated to reflect all of these changes, see them for more details.

  • ValidationErrors is now an []FieldError instead of a map as before.
  • exists tag has been removed, now required tag handles pointer values as well.
  • Much of the design has been updated to use interfaces allowing for even less breaking changes going forward, including FieldError.
  • change name for validating individual fields, I think that some people were associating validation using validate.Field or validate.FieldWithValue to a struct field only, but that is not the case, any variable can be validated and so the functions have been changed to:
var age int

err := validate.Var(age, "gte=0,lte=130")

var parentsAge int

err := validate.VarWithValue(age, parentsAge, "ltcsfield")

// side note: reason validator doesn't have strict sanitizers like IsEmail(..) bool is so many validation can be run  on a field in one run eg.

var settings []string

// this will validate that settings exists, there is at least one entry in array 
// and that each string within the array is set...
validate.Var(settings, "required,gte=1,dive,required")
  • can register any custom tag name function instead of before having to specify the name of the tag...
validate.RegisterTagNameFunc(func(fld reflect.StructField) string {
    name := strings.SplitN(fld.Tag.Get("json"), ",", 2)[0]

    if name == "-" {
        return ""
    }

    return name
})
  • Validation function + Struct Level validation function signatures have changed to use interface and should be infinity easier to remember and implement:
// field level validation func
type Func func(fl FieldLevel) bool

// struct level validation func
type StructLevelFunc func(sl StructLevel)

And now what veryone wants to see, benchmarks compared to v8

benchmark                                               old ns/op     new ns/op     delta
BenchmarkFieldSuccess-8                                 118           108           -8.47%
BenchmarkFieldFailure-8                                 758           320           -57.78%
BenchmarkFieldDiveSuccess-8                             2471          726           -70.62%
BenchmarkFieldDiveFailure-8                             3172          939           -70.40%
BenchmarkFieldCustomTypeSuccess-8                       300           268           -10.67%
BenchmarkFieldCustomTypeFailure-8                       775           310           -60.00%
BenchmarkFieldOrTagSuccess-8                            1122          889           -20.77%
BenchmarkFieldOrTagFailure-8                            1167          546           -53.21%
BenchmarkStructLevelValidationSuccess-8                 548           336           -38.69%
BenchmarkStructLevelValidationFailure-8                 558           611           +9.50%
BenchmarkStructSimpleCustomTypeSuccess-8                623           555           -10.91%
BenchmarkStructSimpleCustomTypeFailure-8                1381          811           -41.27%
BenchmarkStructPartialSuccess-8                         1036          676           -34.75%
BenchmarkStructPartialFailure-8                         1734          1001          -42.27%
BenchmarkStructExceptSuccess-8                          888           1038          +16.89%
BenchmarkStructExceptFailure-8                          1036          863           -16.70%
BenchmarkStructSimpleCrossFieldSuccess-8                773           549           -28.98%
BenchmarkStructSimpleCrossFieldFailure-8                1487          783           -47.34%
BenchmarkStructSimpleCrossStructCrossFieldSuccess-8     1261          837           -33.62%
BenchmarkStructSimpleCrossStructCrossFieldFailure-8     2055          1110          -45.99%
BenchmarkStructSimpleSuccess-8                          519           380           -26.78%
BenchmarkStructSimpleFailure-8                          1429          760           -46.82%
BenchmarkStructSimpleSuccessParallel-8                  146           114           -21.92%
BenchmarkStructSimpleFailureParallel-8                  551           353           -35.93%
BenchmarkStructComplexSuccess-8                         3269          2100          -35.76%
BenchmarkStructComplexFailure-8                         8436          5080          -39.78%
BenchmarkStructComplexSuccessParallel-8                 1024          662           -35.35%
BenchmarkStructComplexFailureParallel-8                 3536          2159          -38.94%

benchmark                                               old allocs     new allocs     delta
BenchmarkFieldSuccess-8                                 0              0              +0.00%
BenchmarkFieldFailure-8                                 4              4              +0.00%
BenchmarkFieldDiveSuccess-8                             28             11             -60.71%
BenchmarkFieldDiveFailure-8                             32             16             -50.00%
BenchmarkFieldCustomTypeSuccess-8                       2              2              +0.00%
BenchmarkFieldCustomTypeFailure-8                       4              4              +0.00%
BenchmarkFieldOrTagSuccess-8                            1              1              +0.00%
BenchmarkFieldOrTagFailure-8                            6              5              -16.67%
BenchmarkStructLevelValidationSuccess-8                 5              2              -60.00%
BenchmarkStructLevelValidationFailure-8                 5              8              +60.00%
BenchmarkStructSimpleCustomTypeSuccess-8                3              2              -33.33%
BenchmarkStructSimpleCustomTypeFailure-8                9              9              +0.00%
BenchmarkStructPartialSuccess-8                         9              6              -33.33%
BenchmarkStructPartialFailure-8                         14             11             -21.43%
BenchmarkStructExceptSuccess-8                          7              12             +71.43%
BenchmarkStructExceptFailure-8                          9              10             +11.11%
BenchmarkStructSimpleCrossFieldSuccess-8                4              3              -25.00%
BenchmarkStructSimpleCrossFieldFailure-8                9              8              -11.11%
BenchmarkStructSimpleCrossStructCrossFieldSuccess-8     7              4              -42.86%
BenchmarkStructSimpleCrossStructCrossFieldFailure-8     12             9              -25.00%
BenchmarkStructSimpleSuccess-8                          1              0              -100.00%
BenchmarkStructSimpleFailure-8                          9              9              +0.00%
BenchmarkStructSimpleSuccessParallel-8                  1              0              -100.00%
BenchmarkStructSimpleFailureParallel-8                  9              9              +0.00%
BenchmarkStructComplexSuccess-8                         15             8              -46.67%
BenchmarkStructComplexFailure-8                         60             53             -11.67%
BenchmarkStructComplexSuccessParallel-8                 15             8              -46.67%
BenchmarkStructComplexFailureParallel-8                 60             53             -11.67%

benchmark                                               old bytes     new bytes     delta
BenchmarkFieldSuccess-8                                 0             0             +0.00%
BenchmarkFieldFailure-8                                 432           192           -55.56%
BenchmarkFieldDiveSuccess-8                             464           201           -56.68%
BenchmarkFieldDiveFailure-8                             896           396           -55.80%
BenchmarkFieldCustomTypeSuccess-8                       32            32            +0.00%
BenchmarkFieldCustomTypeFailure-8                       432           192           -55.56%
BenchmarkFieldOrTagSuccess-8                            4             16            +300.00%
BenchmarkFieldOrTagFailure-8                            448           208           -53.57%
BenchmarkStructLevelValidationSuccess-8                 160           32            -80.00%
BenchmarkStructLevelValidationFailure-8                 160           288           +80.00%
BenchmarkStructSimpleCustomTypeSuccess-8                36            32            -11.11%
BenchmarkStructSimpleCustomTypeFailure-8                640           392           -38.75%
BenchmarkStructPartialSuccess-8                         272           256           -5.88%
BenchmarkStructPartialFailure-8                         730           464           -36.44%
BenchmarkStructExceptSuccess-8                          250           480           +92.00%
BenchmarkStructExceptFailure-8                          272           448           +64.71%
BenchmarkStructSimpleCrossFieldSuccess-8                80            72            -10.00%
BenchmarkStructSimpleCrossFieldFailure-8                536           288           -46.27%
BenchmarkStructSimpleCrossStructCrossFieldSuccess-8     112           80            -28.57%
BenchmarkStructSimpleCrossStructCrossFieldFailure-8     576           304           -47.22%
BenchmarkStructSimpleSuccess-8                          4             0             -100.00%
BenchmarkStructSimpleFailure-8                          640           392           -38.75%
BenchmarkStructSimpleSuccessParallel-8                  4             0             -100.00%
BenchmarkStructSimpleFailureParallel-8                  640           392           -38.75%
BenchmarkStructComplexSuccess-8                         244           128           -47.54%
BenchmarkStructComplexFailure-8                         3609          2833          -21.50%
BenchmarkStructComplexSuccessParallel-8    ...
Read more