Skip to content
Myr

upgrade validator version to v9 (#1015)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* upgrade validator version to v9 * Update vendor.json * Update go.mod * Update go.sum * fix * fix * fix bug * Update binding_test.go * Update validate_test.go * Update go.sum * Update go.mod * Update go.sum * Update go.mod * Update go.sum

authored by thinkerou · committed by GitHub · parent c3f7fc3 · Browse files · 6 files+73 added−42 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+73 added−42 removed

  • other:+73 added−42 removed

6 files+73 added−42 removed

modified:binding/binding_test.go+4 added-4 removed
656 unmodified lines
657 err := JSON.Bind(req, &obj)658 assert.NoError(t, err)659}660661func TestExistsSucceeds(t *testing.T) {661func TestRequiredSucceeds(t *testing.T) {662 type HogeStruct struct {663 Hoge *int `json:"hoge" binding:"exists"`663 Hoge *int `json:"hoge" binding:"required"`664 }665666 var obj HogeStruct667 req := requestWithBody("POST", "/", `{"hoge": 0}`)668 err := JSON.Bind(req, &obj)669 assert.NoError(t, err)670}671672func TestExistsFails(t *testing.T) {672func TestRequiredFails(t *testing.T) {673 type HogeStruct struct {674 Hoge *int `json:"foo" binding:"exists"`674 Hoge *int `json:"foo" binding:"required"`675 }676677 var obj HogeStruct678 req := requestWithBody("POST", "/", `{"boen": 0}`)
563 unmodified lines
modified:binding/default_validator.go+3 added-3 removed
6 unmodified lines
7import (8 "reflect"9 "sync"1011 "gopkg.in/go-playground/validator.v8"11 "gopkg.in/go-playground/validator.v9"12)1314type defaultValidator struct {15 once sync.Once
28 unmodified lines
44}4546func (v *defaultValidator) lazyinit() {47 v.once.Do(func() {48 config := &validator.Config{TagName: "binding"}49 v.validate = validator.New(config)48 v.validate = validator.New()49 v.validate.SetTagName("binding")50 })51}
modified:binding/validate_test.go+3 added-11 removed
4 unmodified lines
5package binding67import (8 "bytes"9 "reflect"9 "testing"10 "time"1112 "github.com/stretchr/testify/assert"14 "gopkg.in/go-playground/validator.v8"13 "gopkg.in/go-playground/validator.v9"14)1516type testInterface interface {17 String() string
180 unmodified lines
198type structCustomValidation struct {199 Integer int `binding:"notone"`200}201203// notOne is a custom validator meant to be used with `validator.v8` library.204// The method signature for `v9` is significantly different and this function205// would need to be changed for tests to pass after upgrade.206// See https://github.com/gin-gonic/gin/pull/1015.207func notOne(208 v *validator.Validate, topStruct reflect.Value, currentStructOrField reflect.Value,209 field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string,210) bool {211 if val, ok := field.Interface().(int); ok {202func notOne(f1 validator.FieldLevel) bool {203 if val, ok := f1.Field().Interface().(int); ok {204 return val != 1205 }206 return false207}
21 unmodified lines
modified:vendor/vendor.json+36 added-6 removed
modified:go.mod+7 added-6 removed
2 unmodified lines
3go 1.1245require (6 github.com/gin-contrib/sse v0.1.07 github.com/go-playground/locales v0.12.1 // indirect8 github.com/go-playground/universal-translator v0.16.0 // indirect7 github.com/golang/protobuf v1.3.18 github.com/json-iterator/go v1.1.69 github.com/golang/protobuf v1.3.210 github.com/json-iterator/go v1.1.711 github.com/leodido/go-urn v1.1.0 // indirect12 github.com/mattn/go-isatty v0.0.910 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect11 github.com/modern-go/reflect2 v1.0.1 // indirect12 github.com/stretchr/testify v1.3.013 github.com/stretchr/testify v1.4.014 github.com/ugorji/go/codec v1.1.715 gopkg.in/go-playground/assert.v1 v1.2.1 // indirect15 gopkg.in/go-playground/validator.v8 v8.18.216 gopkg.in/go-playground/validator.v9 v9.29.117 gopkg.in/yaml.v2 v2.2.218)
modified:go.sum+20 added-12 removed
1github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=1github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=2github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=3github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=4github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=5github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=6github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=7github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs=8github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=5github.com/go-playground/locales v0.12.1 h1:2FITxuFt/xuCNP1Acdhv62OzaCiviiE4kotfhkmOqEc=6github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM=7github.com/go-playground/universal-translator v0.16.0 h1:X++omBR/4cE2MNg91AoC3rmGrCjJ8eAeUP/K/EKx4DM=8github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY=9github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=10github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=11github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=12github.com/json-iterator/go v1.1.7 h1:KfgG9LzI+pYjr4xvmz/5H4FXjokeP+rlHLhv3iH62Fo=13github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=14github.com/leodido/go-urn v1.1.0 h1:Sm1gr51B1kKyfD2BlRcLSiEkffoG96g6TPv6eRoEiB8=15github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=16github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg=17github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=11github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=12github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=13github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=14github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=18github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=19github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=20github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=21github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=22github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=23github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=24github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=18github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=25github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=26github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=27github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=28github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=29github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=30github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=31github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
2 unmodified lines
34gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=35gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=36gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=37gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=30gopkg.in/go-playground/validator.v8 v8.18.2 h1:lFB4DoMU6B626w8ny76MV7VX6W2VHct2GVOI3xgiMrQ=31gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y=38gopkg.in/go-playground/validator.v9 v9.29.1 h1:SvGtYmN60a5CVKTOzMSyfzWDeZRxRuGvRQyEAKbw1xc=39gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=40gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=41gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=