Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: go-playground/validator
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v10.4.1
Choose a base ref
...
head repository: go-playground/validator
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v10.4.2
Choose a head ref
  • 12 commits
  • 12 files changed
  • 11 contributors

Commits on Oct 17, 2020

  1. Github Actions Changeover (#679)

    Dean Karn authored Oct 17, 2020
    Copy the full SHA
    3bb4866 View commit details
  2. split listing into separate job (#680)

    Dean Karn authored Oct 17, 2020
    Copy the full SHA
    f6584a4 View commit details

Commits on Apr 6, 2021

  1. Copy the full SHA
    9c415c4 View commit details
  2. Fix excludedWithoutAll comment (#673)

    Function comment mistakenly referred to a different function
    jfrancisco0 authored Apr 6, 2021
    Copy the full SHA
    514c9db View commit details
  3. Fix accessing fields in composed structs (#733)

    Michał Treter authored Apr 6, 2021
    Copy the full SHA
    ec1baac View commit details
  4. error in spelling (#732)

    Qalifah authored Apr 6, 2021
    Copy the full SHA
    0e67456 View commit details
  5. fix StructLevel Parent() (#716)

    Co-authored-by: torwang <torwang@tencent.com>
    Torwang1 and torwang authored Apr 6, 2021
    Copy the full SHA
    882ec0d View commit details
  6. Copy the full SHA
    5b8f3b8 View commit details
  7. Copy the full SHA
    3c8db83 View commit details
  8. Copy the full SHA
    2b75c46 View commit details
  9. Update errors.go (#671)

    deikatsuo authored Apr 6, 2021
    Copy the full SHA
    526b096 View commit details
  10. Update README.md

    Dean Karn authored Apr 6, 2021
    Copy the full SHA
    6824818 View commit details
Showing with 203 additions and 54 deletions.
  1. +1 −1 .github/CONTRIBUTING.md
  2. +1 −1 .github/ISSUE_TEMPLATE.md
  3. +2 −8 .github/PULL_REQUEST_TEMPLATE.md
  4. +48 −0 .github/workflows/workflow.yml
  5. +0 −29 .travis.yml
  6. +4 −4 README.md
  7. +1 −1 _examples/struct-level/main.go
  8. +4 −1 baked_in.go
  9. +1 −1 errors.go
  10. +2 −2 validator.go
  11. +10 −2 validator_instance.go
  12. +129 −4 validator_test.go
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

## Quality Standard

To ensure the continued stability of this package, tests are required to be written or already exist in order for a pull request to be merged.
To ensure the continued stability of this package, tests are required that cover the change in order for a pull request to be merged.

## Reporting issues

2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### Package version eg. v8, v9:
### Package version eg. v9, v10:



10 changes: 2 additions & 8 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
Fixes Or Enhances # .
## Fixes Or Enhances


**Make sure that you've checked the boxes below before you submit PR:**
- [ ] Tests exist or have been written that cover this particular change.

Change Details:

-
-
-


@go-playground/admins
48 changes: 48 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
on:
push:
branches:
- master
pull_request:
name: Test
jobs:
test:
strategy:
matrix:
go-version: [1.14.x, 1.15.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v2

- name: Restore Cache
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-v1-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-v1-go-
- name: Test
run: go test -race -covermode=atomic -coverprofile="profile.cov" ./...

- name: Send Coverage
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.15.x'
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: profile.cov

golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.31
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package validator
================
<img align="right" src="https://raw.githubusercontent.com/go-playground/validator/v9/logo.png">[![Join the chat at https://gitter.im/go-playground/validator](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-playground/validator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
![Project status](https://img.shields.io/badge/version-10.4.1-green.svg)
![Project status](https://img.shields.io/badge/version-10.4.2-green.svg)
[![Build Status](https://travis-ci.org/go-playground/validator.svg?branch=master)](https://travis-ci.org/go-playground/validator)
[![Coverage Status](https://coveralls.io/repos/go-playground/validator/badge.svg?branch=master&service=github)](https://coveralls.io/github/go-playground/validator?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/validator)](https://goreportcard.com/report/github.com/go-playground/validator)
@@ -27,11 +27,11 @@ Installation

Use go get.

go get github.com/go-playground/validator/v10
go get github.com/go-playground/validator

Then import the validator package into your own code.

import "github.com/go-playground/validator/v10"
import "github.com/go-playground/validator"

Error Return Value
-------
@@ -53,7 +53,7 @@ validationErrors := err.(validator.ValidationErrors)
Usage and documentation
------

Please see https://godoc.org/github.com/go-playground/validator for detailed usage docs.
Please see https://pkg.go.dev/github.com/go-playground/validator/v10 for detailed usage docs.

##### Examples:

2 changes: 1 addition & 1 deletion _examples/struct-level/main.go
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ func main() {

// register validation for 'User'
// NOTE: only have to register a non-pointer type for 'User', validator
// interanlly dereferences during it's type checks.
// internally dereferences during it's type checks.
validate.RegisterStructValidation(UserStructLevelValidation, User{})

// build 'User' info, normally posted data etc...
5 changes: 4 additions & 1 deletion baked_in.go
Original file line number Diff line number Diff line change
@@ -791,6 +791,9 @@ func isNeField(fl FieldLevel) bool {
case reflect.Slice, reflect.Map, reflect.Array:
return int64(field.Len()) != int64(currentField.Len())

case reflect.Bool:
return field.Bool() != currentField.Bool()

case reflect.Struct:

fieldType := field.Type()
@@ -1544,7 +1547,7 @@ func requiredWithout(fl FieldLevel) bool {
return true
}

// RequiredWithoutAll is the validation function
// ExcludedWithoutAll is the validation function
// The field under validation must not be present or is empty when all of the other specified fields are not present.
func excludedWithoutAll(fl FieldLevel) bool {
params := parseOneOfParam2(fl.Param())
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
@@ -146,7 +146,7 @@ type FieldError interface {

// Type returns the Field's reflect Type
//
// // eg. time.Time's type is time.Time
// eg. time.Time's type is time.Time
Type() reflect.Type

// returns the FieldError's translated error
4 changes: 2 additions & 2 deletions validator.go
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ func (v *validate) validateStruct(ctx context.Context, parent reflect.Value, cur
}
}

v.traverseField(ctx, parent, current.Field(f.idx), ns, structNs, f, f.cTags)
v.traverseField(ctx, current, current.Field(f.idx), ns, structNs, f, f.cTags)
}
}

@@ -222,7 +222,7 @@ func (v *validate) traverseField(ctx context.Context, parent reflect.Value, curr
structNs = append(append(structNs, cf.name...), '.')
}

v.validateStruct(ctx, current, current, typ, ns, structNs, ct)
v.validateStruct(ctx, parent, current, typ, ns, structNs, ct)
return
}
}
12 changes: 10 additions & 2 deletions validator_instance.go
Original file line number Diff line number Diff line change
@@ -29,6 +29,10 @@ const (
requiredWithAllTag = "required_with_all"
requiredIfTag = "required_if"
requiredUnlessTag = "required_unless"
excludedWithoutAllTag = "excluded_without_all"
excludedWithoutTag = "excluded_without"
excludedWithTag = "excluded_with"
excludedWithAllTag = "excluded_with_all"
skipValidationTag = "-"
diveTag = "dive"
keysTag = "keys"
@@ -111,7 +115,8 @@ func New() *Validate {

switch k {
// these require that even if the value is nil that the validation should run, omitempty still overrides this behaviour
case requiredIfTag, requiredUnlessTag, requiredWithTag, requiredWithAllTag, requiredWithoutTag, requiredWithoutAllTag:
case requiredIfTag, requiredUnlessTag, requiredWithTag, requiredWithAllTag, requiredWithoutTag, requiredWithoutAllTag,
excludedWithTag, excludedWithAllTag, excludedWithoutTag, excludedWithoutAllTag:
_ = v.registerValidation(k, wrapFunc(val), true, true)
default:
// no need to error check here, baked in will always be valid
@@ -409,7 +414,10 @@ func (v *Validate) StructPartialCtx(ctx context.Context, s interface{}, fields .
if len(flds) > 0 {

vd.misc = append(vd.misc[0:0], name...)
vd.misc = append(vd.misc, '.')
// Don't append empty name for unnamed structs
if len(vd.misc) != 0 {
vd.misc = append(vd.misc, '.')
}

for _, s := range flds {

Loading