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
Provenance
- Commit
1acb3fb- Tree
82e585d- Author
thinkerou <thinkerou@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
c3f7fc3
6 files changed+73 added−42 removed
modified:binding/binding_test.go+4 added-4 removed
656 unmodified lines657 err := JSON.Bind(req, &obj)658 assert.NoError(t, err)659 }660 661-func TestExistsSucceeds(t *testing.T) {661+func TestRequiredSucceeds(t *testing.T) {662 type HogeStruct struct {663- Hoge *int `json:"hoge" binding:"exists"`663+ Hoge *int `json:"hoge" binding:"required"`664 }665 666 var obj HogeStruct667 req := requestWithBody("POST", "/", `{"hoge": 0}`)668 err := JSON.Bind(req, &obj)669 assert.NoError(t, err)670 }671 672-func TestExistsFails(t *testing.T) {672+func TestRequiredFails(t *testing.T) {673 type HogeStruct struct {674- Hoge *int `json:"foo" binding:"exists"`674+ Hoge *int `json:"foo" binding:"required"`675 }676 677 var obj HogeStruct678 req := requestWithBody("POST", "/", `{"boen": 0}`)563 unmodified linesmodified:binding/default_validator.go+3 added-3 removed
6 unmodified lines7 import (8 "reflect"9 "sync"10 11- "gopkg.in/go-playground/validator.v8"11+ "gopkg.in/go-playground/validator.v9"12 )13 14 type defaultValidator struct {15 once sync.Once28 unmodified lines44 }45 46 func (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 lines5 package binding6 7 import (8 "bytes"9- "reflect"9 "testing"10 "time"11 12 "github.com/stretchr/testify/assert"14- "gopkg.in/go-playground/validator.v8"13+ "gopkg.in/go-playground/validator.v9"14 )15 16 type testInterface interface {17 String() string180 unmodified lines198 type structCustomValidation struct {199 Integer int `binding:"notone"`200 }201 203-// 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.207-func 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 {202+func notOne(f1 validator.FieldLevel) bool {203+ if val, ok := f1.Field().Interface().(int); ok {204 return val != 1205 }206 return false207 }21 unmodified linesmodified:vendor/vendor.json+36 added-6 removed
17 unmodified lines1819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626362 unmodified lines1261271281291001011021031041051301311321331341351361371381398 unmodified lines17 unmodified lines "version": "v0.1", "versionExact": "v0.1.0" }, { "checksumSHA1": "b4DmyMT9bicTRVJw1hJXHLhIH+0=", "path": "github.com/go-playground/locales", "revision": "f63010822830b6fe52288ee52d5a1151088ce039", "revisionTime": "2018-03-23T16:04:04Z", "version": "v0.12", "versionExact": "v0.12.1" }, { "checksumSHA1": "JgF260rC9YpWyY5WEljjimWLUXs=", "path": "github.com/go-playground/locales/currency", "revision": "630ebbb602847eba93e75ae38bbc7bb7abcf1ff3", "revisionTime": "2019-04-30T15:33:29Z" }, { "checksumSHA1": "9pKcUHBaVS+360X6h4IowhmOPjk=", "path": "github.com/go-playground/universal-translator", "revision": "b32fa301c9fe55953584134cb6853a13c87ec0a1", "revisionTime": "2017-02-09T16:11:52Z", "version": "v0.16", "versionExact": "v0.16.0" }, { "checksumSHA1": "Y2MOwzNZfl4NRNDbLCZa6sgx7O0=", "path": "github.com/golang/protobuf/proto", "revision": "c823c79ea1570fb5ff454033735a8e68575d1d0f", "revisionTime": "2019-02-05T22:20:52Z", "version": "v1.3", "versionExact": "v1.3.0" }, { "checksumSHA1": "zNo6yGy/bCJuzkEcP70oEBtOB2M=", "path": "github.com/leodido/go-urn", "revision": "70078a794e8ea4b497ba7c19a78cd60f90ccf0f4", "revisionTime": "2018-05-24T03:26:21Z", "version": "v1.1", "versionExact": "v1.1.0" }, { "checksumSHA1": "TB2vxux9xQbvsTHOVt4aRTuvSn4=", "path": "github.com/json-iterator/go", "revision": "0ff49de124c6f76f8494e194af75bde0f1a49a29", "revisionTime": "2019-03-06T14:29:09Z",62 unmodified lines "revision": "a43fa875dd822b81eb6d2ad538bc1f4caba169bd", "revisionTime": "2019-05-02T15:41:39Z" }, { "checksumSHA1": "P/k5ZGf0lEBgpKgkwy++F7K1PSg=", "path": "gopkg.in/go-playground/validator.v8", "revision": "5f1438d3fca68893a817e4a66806cea46a9e4ebf", "revisionTime": "2017-07-30T05:02:35Z", "version": "v8.18.2", "versionExact": "v8.18.2" "checksumSHA1": "ACzc7AkwLtNgKhqtj8V7SGUJgnw=", "path": "gopkg.in/go-playground/validator.v9", "revision": "46b4b1e301c24cac870ffcb4ba5c8a703d1ef475", "revisionTime": "2019-03-31T13:31:25Z", "version": "v9.28", "versionExact": "v9.28.0" }, { "checksumSHA1": "QqDq2x8XOU7IoOR98Cx1eiV5QY8=", "path": "gopkg.in/yaml.v2",8 unmodified linesmodified:go.mod+7 added-6 removed
2 unmodified lines3 go 1.124 5 require (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
1-github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=1 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=2+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=3 github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=4 github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=5-github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=6-github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=7-github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs=8-github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=5+github.com/go-playground/locales v0.12.1 h1:2FITxuFt/xuCNP1Acdhv62OzaCiviiE4kotfhkmOqEc=6+github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM=7+github.com/go-playground/universal-translator v0.16.0 h1:X++omBR/4cE2MNg91AoC3rmGrCjJ8eAeUP/K/EKx4DM=8+github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY=9+github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=10+github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=11+github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=12+github.com/json-iterator/go v1.1.7 h1:KfgG9LzI+pYjr4xvmz/5H4FXjokeP+rlHLhv3iH62Fo=13+github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=14+github.com/leodido/go-urn v1.1.0 h1:Sm1gr51B1kKyfD2BlRcLSiEkffoG96g6TPv6eRoEiB8=15+github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=16 github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg=17 github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=11-github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=12-github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=13-github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=14-github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=18+github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=19+github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=20+github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=21+github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=22 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=23 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=24 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=18-github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=25 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=26+github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=27+github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=28 github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=29 github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=30 github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=31 github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=2 unmodified lines34 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=35 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=36 gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=37 gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=30-gopkg.in/go-playground/validator.v8 v8.18.2 h1:lFB4DoMU6B626w8ny76MV7VX6W2VHct2GVOI3xgiMrQ=31-gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y=38+gopkg.in/go-playground/validator.v9 v9.29.1 h1:SvGtYmN60a5CVKTOzMSyfzWDeZRxRuGvRQyEAKbw1xc=39+gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=40 gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=41 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=