parent
cd1bd58169
commit
7e57ca0cf5
@ -0,0 +1,29 @@ |
|||||||
|
language: go |
||||||
|
go: |
||||||
|
- 1.13.4 |
||||||
|
- tip |
||||||
|
matrix: |
||||||
|
allow_failures: |
||||||
|
- go: tip |
||||||
|
|
||||||
|
notifications: |
||||||
|
email: |
||||||
|
recipients: dean.karn@gmail.com |
||||||
|
on_success: change |
||||||
|
on_failure: always |
||||||
|
|
||||||
|
before_install: |
||||||
|
- go install github.com/mattn/goveralls |
||||||
|
- mkdir -p $GOPATH/src/gopkg.in |
||||||
|
- ln -s $GOPATH/src/github.com/$TRAVIS_REPO_SLUG $GOPATH/src/gopkg.in/validator.v9 |
||||||
|
|
||||||
|
# Only clone the most recent commit. |
||||||
|
git: |
||||||
|
depth: 1 |
||||||
|
|
||||||
|
script: |
||||||
|
- go test -v -race -covermode=atomic -coverprofile=coverage.coverprofile ./... |
||||||
|
|
||||||
|
after_success: | |
||||||
|
[ $TRAVIS_GO_VERSION = 1.13.4 ] && |
||||||
|
goveralls -coverprofile=coverage.coverprofile -service travis-ci -repotoken $COVERALLS_TOKEN |
@ -1,83 +0,0 @@ |
|||||||
package validator_test |
|
||||||
|
|
||||||
// import (
|
|
||||||
// "fmt"
|
|
||||||
|
|
||||||
// "gopkg.in/go-playground/validator.v8"
|
|
||||||
// )
|
|
||||||
|
|
||||||
// func ExampleValidate_new() {
|
|
||||||
// config := &validator.Config{TagName: "validate"}
|
|
||||||
|
|
||||||
// validator.New(config)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func ExampleValidate_field() {
|
|
||||||
// // This should be stored somewhere globally
|
|
||||||
// var validate *validator.Validate
|
|
||||||
|
|
||||||
// config := &validator.Config{TagName: "validate"}
|
|
||||||
|
|
||||||
// validate = validator.New(config)
|
|
||||||
|
|
||||||
// i := 0
|
|
||||||
// errs := validate.Field(i, "gt=1,lte=10")
|
|
||||||
// err := errs.(validator.ValidationErrors)[""]
|
|
||||||
// fmt.Println(err.Field)
|
|
||||||
// fmt.Println(err.Tag)
|
|
||||||
// fmt.Println(err.Kind) // NOTE: Kind and Type can be different i.e. time Kind=struct and Type=time.Time
|
|
||||||
// fmt.Println(err.Type)
|
|
||||||
// fmt.Println(err.Param)
|
|
||||||
// fmt.Println(err.Value)
|
|
||||||
// //Output:
|
|
||||||
// //
|
|
||||||
// //gt
|
|
||||||
// //int
|
|
||||||
// //int
|
|
||||||
// //1
|
|
||||||
// //0
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func ExampleValidate_struct() {
|
|
||||||
// // This should be stored somewhere globally
|
|
||||||
// var validate *validator.Validate
|
|
||||||
|
|
||||||
// config := &validator.Config{TagName: "validate"}
|
|
||||||
|
|
||||||
// validate = validator.New(config)
|
|
||||||
|
|
||||||
// type ContactInformation struct {
|
|
||||||
// Phone string `validate:"required"`
|
|
||||||
// Street string `validate:"required"`
|
|
||||||
// City string `validate:"required"`
|
|
||||||
// }
|
|
||||||
|
|
||||||
// type User struct {
|
|
||||||
// Name string `validate:"required,excludesall=!@#$%^&*()_+-=:;?/0x2C"` // 0x2C = comma (,)
|
|
||||||
// Age int8 `validate:"required,gt=0,lt=150"`
|
|
||||||
// Email string `validate:"email"`
|
|
||||||
// ContactInformation []*ContactInformation
|
|
||||||
// }
|
|
||||||
|
|
||||||
// contactInfo := &ContactInformation{
|
|
||||||
// Street: "26 Here Blvd.",
|
|
||||||
// City: "Paradeso",
|
|
||||||
// }
|
|
||||||
|
|
||||||
// user := &User{
|
|
||||||
// Name: "Joey Bloggs",
|
|
||||||
// Age: 31,
|
|
||||||
// Email: "joeybloggs@gmail.com",
|
|
||||||
// ContactInformation: []*ContactInformation{contactInfo},
|
|
||||||
// }
|
|
||||||
|
|
||||||
// errs := validate.Struct(user)
|
|
||||||
// for _, v := range errs.(validator.ValidationErrors) {
|
|
||||||
// fmt.Println(v.Field) // Phone
|
|
||||||
// fmt.Println(v.Tag) // required
|
|
||||||
// //... and so forth
|
|
||||||
// //Output:
|
|
||||||
// //Phone
|
|
||||||
// //required
|
|
||||||
// }
|
|
||||||
// }
|
|
@ -0,0 +1,10 @@ |
|||||||
|
module github.com/go-playground/validator/v10 |
||||||
|
|
||||||
|
go 1.13 |
||||||
|
|
||||||
|
require ( |
||||||
|
github.com/go-playground/assert/v2 v2.0.1 |
||||||
|
github.com/go-playground/locales v0.13.0 |
||||||
|
github.com/go-playground/universal-translator v0.17.0 |
||||||
|
github.com/leodido/go-urn v1.2.0 |
||||||
|
) |
@ -0,0 +1,21 @@ |
|||||||
|
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= |
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
||||||
|
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= |
||||||
|
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= |
||||||
|
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= |
||||||
|
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= |
||||||
|
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= |
||||||
|
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= |
||||||
|
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= |
||||||
|
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= |
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= |
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= |
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= |
||||||
|
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= |
||||||
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= |
||||||
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= |
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= |
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= |
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= |
||||||
|
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= |
||||||
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
Loading…
Reference in new issue