Codebase list golang-github-go-playground-validator-v10 / 7e57ca0
convert to go modules Dean Karn 4 years ago
34 changed file(s) with 114 addition(s) and 137 deletion(s). Raw diff Collapse all Expand all
0 language: go
1 go:
2 - 1.13.4
3 - tip
4 matrix:
5 allow_failures:
6 - go: tip
7
8 notifications:
9 email:
10 recipients: dean.karn@gmail.com
11 on_success: change
12 on_failure: always
13
14 before_install:
15 - go install github.com/mattn/goveralls
16 - mkdir -p $GOPATH/src/gopkg.in
17 - ln -s $GOPATH/src/github.com/$TRAVIS_REPO_SLUG $GOPATH/src/gopkg.in/validator.v9
18
19 # Only clone the most recent commit.
20 git:
21 depth: 1
22
23 script:
24 - go test -v -race -covermode=atomic -coverprofile=coverage.coverprofile ./...
25
26 after_success: |
27 [ $TRAVIS_GO_VERSION = 1.13.4 ] &&
28 goveralls -coverprofile=coverage.coverprofile -service travis-ci -repotoken $COVERALLS_TOKEN
0 GOCMD=go
0 GOCMD=GO111MODULE=on go
11
22 linters-install:
33 @golangci-lint --version >/dev/null 2>&1 || { \
44 echo "installing linting tools..."; \
5 curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.19.1; \
5 curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.21.0; \
66 }
77
88 lint: linters-install
9 golangci-lint run
9 $(PWD)/bin/golangci-lint run
1010
1111 test:
1212 $(GOCMD) test -cover -race ./...
00 Package validator
11 ================
22 <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)
3 ![Project status](https://img.shields.io/badge/version-9.30.0-green.svg)
4 [![Build Status](https://semaphoreci.com/api/v1/joeybloggs/validator/branches/v9/badge.svg)](https://semaphoreci.com/joeybloggs/validator)
5 [![Coverage Status](https://coveralls.io/repos/go-playground/validator/badge.svg?branch=v9&service=github)](https://coveralls.io/github/go-playground/validator?branch=v9)
3 ![Project status](https://img.shields.io/badge/version-10.0.0-green.svg)
4 [![Build Status](https://travis-ci.org/go-playground/validator.svg?branch=master)](https://travis-ci.org/go-playground/validator)
5 [![Coverage Status](https://coveralls.io/repos/go-playground/validator/badge.svg?branch=master&service=github)](https://coveralls.io/github/go-playground/validator?branch=master)
66 [![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/validator)](https://goreportcard.com/report/github.com/go-playground/validator)
7 [![GoDoc](https://godoc.org/gopkg.in/go-playground/validator.v9?status.svg)](https://godoc.org/gopkg.in/go-playground/validator.v9)
7 [![GoDoc](https://godoc.org/github.com/go-playground/validator?status.svg)](https://godoc.org/github.com/go-playground/validator)
88 ![License](https://img.shields.io/dub/l/vibe-d.svg)
99
1010 Package validator implements value validations for structs and individual fields based on tags.
1919 - Alias validation tags, which allows for mapping of several validations to a single tag for easier defining of validations on structs
2020 - Extraction of custom defined Field Name e.g. can specify to extract the JSON name while validating and have it available in the resulting FieldError
2121 - Customizable i18n aware error messages.
22 - Default validator for the [gin](https://github.com/gin-gonic/gin) web framework; upgrading from v8 to v9 in gin see [here](https://github.com/go-playground/validator/tree/v9/_examples/gin-upgrading-overriding)
22 - Default validator for the [gin](https://github.com/gin-gonic/gin) web framework; upgrading from v8 to v9 in gin see [here](https://github.com/go-playground/validator/tree/master/_examples/gin-upgrading-overriding)
2323
2424 Installation
2525 ------------
2626
2727 Use go get.
2828
29 go get gopkg.in/go-playground/validator.v9
29 go get github.com/go-playground/validator/v10
3030
3131 Then import the validator package into your own code.
3232
33 import "gopkg.in/go-playground/validator.v9"
33 import "github.com/go-playground/validator/v10"
3434
3535 Error Return Value
3636 -------
5252 Usage and documentation
5353 ------
5454
55 Please see http://godoc.org/gopkg.in/go-playground/validator.v9 for detailed usage docs.
55 Please see http://godoc.org/github.com/go-playground/validator/v10 for detailed usage docs.
5656
5757 ##### Examples:
5858
59 - [Simple](https://github.com/go-playground/validator/blob/v9/_examples/simple/main.go)
60 - [Custom Field Types](https://github.com/go-playground/validator/blob/v9/_examples/custom/main.go)
61 - [Struct Level](https://github.com/go-playground/validator/blob/v9/_examples/struct-level/main.go)
62 - [Translations & Custom Errors](https://github.com/go-playground/validator/blob/v9/_examples/translations/main.go)
59 - [Simple](https://github.com/go-playground/validator/blob/master/_examples/simple/main.go)
60 - [Custom Field Types](https://github.com/go-playground/validator/blob/master/_examples/custom/main.go)
61 - [Struct Level](https://github.com/go-playground/validator/blob/master/_examples/struct-level/main.go)
62 - [Translations & Custom Errors](https://github.com/go-playground/validator/blob/master/_examples/translations/main.go)
6363 - [Gin upgrade and/or override validator](https://github.com/go-playground/validator/tree/v9/_examples/gin-upgrading-overriding)
6464 - [wash - an example application putting it all together](https://github.com/bluesuncorp/wash)
6565
55 "fmt"
66 "reflect"
77
8 "gopkg.in/go-playground/validator.v9"
8 "github.com/go-playground/validator/v10"
99 )
1010
1111 // DbBackedUser User struct
22 import (
33 "fmt"
44
5 "gopkg.in/go-playground/validator.v9"
5 "github.com/go-playground/validator/v10"
66 )
77
88 // MyStruct ..
22 import (
33 "fmt"
44
5 "gopkg.in/go-playground/validator.v9"
5 "github.com/go-playground/validator/v10"
66 )
77
88 // Test ...
44 "sync"
55
66 "github.com/gin-gonic/gin/binding"
7 "gopkg.in/go-playground/validator.v9"
7 "github.com/go-playground/validator/v10"
88 )
99
1010 type defaultValidator struct {
22 import (
33 "fmt"
44
5 "gopkg.in/go-playground/validator.v9"
5 "github.com/go-playground/validator/v10"
66 )
77
88 // User contains user information
22 import (
33 "fmt"
44
5 "gopkg.in/go-playground/validator.v9"
5 "github.com/go-playground/validator/v10"
66 )
77
88 // User contains user information
44
55 "github.com/go-playground/locales/en"
66 ut "github.com/go-playground/universal-translator"
7 "gopkg.in/go-playground/validator.v9"
8 en_translations "gopkg.in/go-playground/validator.v9/translations/en"
7 "github.com/go-playground/validator/v10"
8 en_translations "github.com/go-playground/validator/v10/translations/en"
99 )
1010
1111 // User contains user information
+0
-83
examples_test.go less more
0 package validator_test
1
2 // import (
3 // "fmt"
4
5 // "gopkg.in/go-playground/validator.v8"
6 // )
7
8 // func ExampleValidate_new() {
9 // config := &validator.Config{TagName: "validate"}
10
11 // validator.New(config)
12 // }
13
14 // func ExampleValidate_field() {
15 // // This should be stored somewhere globally
16 // var validate *validator.Validate
17
18 // config := &validator.Config{TagName: "validate"}
19
20 // validate = validator.New(config)
21
22 // i := 0
23 // errs := validate.Field(i, "gt=1,lte=10")
24 // err := errs.(validator.ValidationErrors)[""]
25 // fmt.Println(err.Field)
26 // fmt.Println(err.Tag)
27 // fmt.Println(err.Kind) // NOTE: Kind and Type can be different i.e. time Kind=struct and Type=time.Time
28 // fmt.Println(err.Type)
29 // fmt.Println(err.Param)
30 // fmt.Println(err.Value)
31 // //Output:
32 // //
33 // //gt
34 // //int
35 // //int
36 // //1
37 // //0
38 // }
39
40 // func ExampleValidate_struct() {
41 // // This should be stored somewhere globally
42 // var validate *validator.Validate
43
44 // config := &validator.Config{TagName: "validate"}
45
46 // validate = validator.New(config)
47
48 // type ContactInformation struct {
49 // Phone string `validate:"required"`
50 // Street string `validate:"required"`
51 // City string `validate:"required"`
52 // }
53
54 // type User struct {
55 // Name string `validate:"required,excludesall=!@#$%^&*()_+-=:;?/0x2C"` // 0x2C = comma (,)
56 // Age int8 `validate:"required,gt=0,lt=150"`
57 // Email string `validate:"email"`
58 // ContactInformation []*ContactInformation
59 // }
60
61 // contactInfo := &ContactInformation{
62 // Street: "26 Here Blvd.",
63 // City: "Paradeso",
64 // }
65
66 // user := &User{
67 // Name: "Joey Bloggs",
68 // Age: 31,
69 // Email: "joeybloggs@gmail.com",
70 // ContactInformation: []*ContactInformation{contactInfo},
71 // }
72
73 // errs := validate.Struct(user)
74 // for _, v := range errs.(validator.ValidationErrors) {
75 // fmt.Println(v.Field) // Phone
76 // fmt.Println(v.Tag) // required
77 // //... and so forth
78 // //Output:
79 // //Phone
80 // //required
81 // }
82 // }
0 module github.com/go-playground/validator/v10
1
2 go 1.13
3
4 require (
5 github.com/go-playground/assert/v2 v2.0.1
6 github.com/go-playground/locales v0.13.0
7 github.com/go-playground/universal-translator v0.17.0
8 github.com/leodido/go-urn v1.2.0
9 )
0 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/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
3 github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
4 github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
5 github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
6 github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
7 github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
8 github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
9 github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
10 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
11 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
12 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
13 github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
14 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
15 golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
16 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
17 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
18 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
19 gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
20 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
33 "reflect"
44 "strings"
55
6 "gopkg.in/go-playground/validator.v9"
6 "github.com/go-playground/validator/v10"
77 )
88
99 // NotBlank is the validation function for validating if the current field
22 import (
33 "testing"
44
5 "gopkg.in/go-playground/validator.v9"
6 "gopkg.in/go-playground/assert.v1"
5 "github.com/go-playground/validator/v10"
6 "github.com/go-playground/assert/v2"
77 )
88
99 type test struct {
99
1010 "github.com/go-playground/locales"
1111 ut "github.com/go-playground/universal-translator"
12 "gopkg.in/go-playground/validator.v9"
12 "github.com/go-playground/validator/v10"
1313 )
1414
1515 // RegisterDefaultTranslations registers a set of default translations
55
66 english "github.com/go-playground/locales/en"
77 ut "github.com/go-playground/universal-translator"
8 . "gopkg.in/go-playground/assert.v1"
9 "gopkg.in/go-playground/validator.v9"
8 . "github.com/go-playground/assert/v2"
9 "github.com/go-playground/validator/v10"
1010 )
1111
1212 func TestTranslations(t *testing.T) {
99
1010 "github.com/go-playground/locales"
1111 ut "github.com/go-playground/universal-translator"
12 "gopkg.in/go-playground/validator.v9"
12 "github.com/go-playground/validator/v10"
1313 )
1414
1515 // RegisterDefaultTranslations registers a set of default translations
55
66 french "github.com/go-playground/locales/fr"
77 ut "github.com/go-playground/universal-translator"
8 . "gopkg.in/go-playground/assert.v1"
9 "gopkg.in/go-playground/validator.v9"
8 . "github.com/go-playground/assert/v2"
9 "github.com/go-playground/validator/v10"
1010 )
1111
1212 func TestTranslations(t *testing.T) {
99
1010 "github.com/go-playground/locales"
1111 ut "github.com/go-playground/universal-translator"
12 "gopkg.in/go-playground/validator.v9"
12 "github.com/go-playground/validator/v10"
1313 )
1414
1515 // RegisterDefaultTranslations registers a set of default translations
55
66 indonesia "github.com/go-playground/locales/id"
77 ut "github.com/go-playground/universal-translator"
8 . "gopkg.in/go-playground/assert.v1"
9 "gopkg.in/go-playground/validator.v9"
8 . "github.com/go-playground/assert/v2"
9 "github.com/go-playground/validator/v10"
1010 )
1111
1212 func TestTranslations(t *testing.T) {
99
1010 "github.com/go-playground/locales"
1111 ut "github.com/go-playground/universal-translator"
12 "gopkg.in/go-playground/validator.v9"
12 "github.com/go-playground/validator/v10"
1313 )
1414
1515 // RegisterDefaultTranslations registers a set of default translations
55
66 ja_locale "github.com/go-playground/locales/ja"
77 ut "github.com/go-playground/universal-translator"
8 . "gopkg.in/go-playground/assert.v1"
9 "gopkg.in/go-playground/validator.v9"
8 . "github.com/go-playground/assert/v2"
9 "github.com/go-playground/validator/v10"
1010 )
1111
1212 func TestTranslations(t *testing.T) {
99
1010 "github.com/go-playground/locales"
1111 ut "github.com/go-playground/universal-translator"
12 "gopkg.in/go-playground/validator.v9"
12 "github.com/go-playground/validator/v10"
1313 )
1414
1515 // RegisterDefaultTranslations registers a set of default translations
55
66 english "github.com/go-playground/locales/en"
77 ut "github.com/go-playground/universal-translator"
8 . "gopkg.in/go-playground/assert.v1"
9 "gopkg.in/go-playground/validator.v9"
8 . "github.com/go-playground/assert/v2"
9 "github.com/go-playground/validator/v10"
1010 )
1111
1212 func TestTranslations(t *testing.T) {
99
1010 "github.com/go-playground/locales"
1111 ut "github.com/go-playground/universal-translator"
12 "gopkg.in/go-playground/validator.v9"
12 "github.com/go-playground/validator/v10"
1313 )
1414
1515 // RegisterDefaultTranslations registers a set of default translations
55
66 brazilian_portuguese "github.com/go-playground/locales/pt_BR"
77 ut "github.com/go-playground/universal-translator"
8 "gopkg.in/go-playground/validator.v9"
9 . "gopkg.in/go-playground/assert.v1"
8 "github.com/go-playground/validator/v10"
9 . "github.com/go-playground/assert/v2"
1010 )
1111
1212 func TestTranslations(t *testing.T) {
99
1010 "github.com/go-playground/locales"
1111 ut "github.com/go-playground/universal-translator"
12 "gopkg.in/go-playground/validator.v9"
12 "github.com/go-playground/validator/v10"
1313 )
1414
1515 // RegisterDefaultTranslations registers a set of default translations
55
66 turkish "github.com/go-playground/locales/tr"
77 ut "github.com/go-playground/universal-translator"
8 . "gopkg.in/go-playground/assert.v1"
9 "gopkg.in/go-playground/validator.v9"
8 . "github.com/go-playground/assert/v2"
9 "github.com/go-playground/validator/v10"
1010 )
1111
1212 func TestTranslations(t *testing.T) {
99
1010 "github.com/go-playground/locales"
1111 ut "github.com/go-playground/universal-translator"
12 "gopkg.in/go-playground/validator.v9"
12 "github.com/go-playground/validator/v10"
1313 )
1414
1515 // RegisterDefaultTranslations registers a set of default translations
55
66 zhongwen "github.com/go-playground/locales/zh"
77 ut "github.com/go-playground/universal-translator"
8 . "gopkg.in/go-playground/assert.v1"
9 "gopkg.in/go-playground/validator.v9"
8 . "github.com/go-playground/assert/v2"
9 "github.com/go-playground/validator/v10"
1010 )
1111
1212 func TestTranslations(t *testing.T) {
99
1010 "github.com/go-playground/locales"
1111 ut "github.com/go-playground/universal-translator"
12 "gopkg.in/go-playground/validator.v9"
12 "github.com/go-playground/validator/v10"
1313 )
1414
1515 // RegisterDefaultTranslations registers a set of default translations
55
66 zhongwen "github.com/go-playground/locales/zh_Hant_TW"
77 ut "github.com/go-playground/universal-translator"
8 . "gopkg.in/go-playground/assert.v1"
9 "gopkg.in/go-playground/validator.v9"
8 . "github.com/go-playground/assert/v2"
9 "github.com/go-playground/validator/v10"
1010 )
1111
1212 func TestTranslations(t *testing.T) {
1717 "github.com/go-playground/locales/fr"
1818 "github.com/go-playground/locales/nl"
1919 ut "github.com/go-playground/universal-translator"
20 . "gopkg.in/go-playground/assert.v1"
20 . "github.com/go-playground/assert/v2"
2121 )
2222
2323 // NOTES: