convert to go modules

pull/539/head v10.0.0
Dean Karn 5 years ago
parent cd1bd58169
commit 7e57ca0cf5
  1. 29
      .travis.yml
  2. 6
      Makefile
  3. 24
      README.md
  4. 2
      _examples/custom-validation/main.go
  5. 2
      _examples/custom/main.go
  6. 2
      _examples/dive/main.go
  7. 2
      _examples/gin-upgrading-overriding/v8_to_v9.go
  8. 2
      _examples/simple/main.go
  9. 2
      _examples/struct-level/main.go
  10. 4
      _examples/translations/main.go
  11. 83
      examples_test.go
  12. 10
      go.mod
  13. 21
      go.sum
  14. 2
      non-standard/validators/notblank.go
  15. 4
      non-standard/validators/notblank_test.go
  16. 2
      translations/en/en.go
  17. 4
      translations/en/en_test.go
  18. 2
      translations/fr/fr.go
  19. 4
      translations/fr/fr_test.go
  20. 2
      translations/id/id.go
  21. 4
      translations/id/id_test.go
  22. 2
      translations/ja/ja.go
  23. 4
      translations/ja/ja_test.go
  24. 2
      translations/nl/nl.go
  25. 4
      translations/nl/nl_test.go
  26. 2
      translations/pt_BR/pt_BR.go
  27. 4
      translations/pt_BR/pt_BR_test.go
  28. 2
      translations/tr/tr.go
  29. 4
      translations/tr/tr_test.go
  30. 2
      translations/zh/zh.go
  31. 4
      translations/zh/zh_test.go
  32. 2
      translations/zh_tw/zh_tw.go
  33. 4
      translations/zh_tw/zh_tw_test.go
  34. 2
      validator_test.go

@ -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,13 +1,13 @@
GOCMD=go
GOCMD=GO111MODULE=on go
linters-install:
@golangci-lint --version >/dev/null 2>&1 || { \
echo "installing linting tools..."; \
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.19.1; \
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.21.0; \
}
lint: linters-install
golangci-lint run
$(PWD)/bin/golangci-lint run
test:
$(GOCMD) test -cover -race ./...

@ -1,11 +1,11 @@
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-9.30.0-green.svg)
[![Build Status](https://semaphoreci.com/api/v1/joeybloggs/validator/branches/v9/badge.svg)](https://semaphoreci.com/joeybloggs/validator)
[![Coverage Status](https://coveralls.io/repos/go-playground/validator/badge.svg?branch=v9&service=github)](https://coveralls.io/github/go-playground/validator?branch=v9)
![Project status](https://img.shields.io/badge/version-10.0.0-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)
[![GoDoc](https://godoc.org/gopkg.in/go-playground/validator.v9?status.svg)](https://godoc.org/gopkg.in/go-playground/validator.v9)
[![GoDoc](https://godoc.org/github.com/go-playground/validator?status.svg)](https://godoc.org/github.com/go-playground/validator)
![License](https://img.shields.io/dub/l/vibe-d.svg)
Package validator implements value validations for structs and individual fields based on tags.
@ -20,18 +20,18 @@ It has the following **unique** features:
- Alias validation tags, which allows for mapping of several validations to a single tag for easier defining of validations on structs
- 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
- Customizable i18n aware error messages.
- 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)
- 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)
Installation
------------
Use go get.
go get gopkg.in/go-playground/validator.v9
go get github.com/go-playground/validator/v10
Then import the validator package into your own code.
import "gopkg.in/go-playground/validator.v9"
import "github.com/go-playground/validator/v10"
Error Return Value
-------
@ -53,14 +53,14 @@ validationErrors := err.(validator.ValidationErrors)
Usage and documentation
------
Please see http://godoc.org/gopkg.in/go-playground/validator.v9 for detailed usage docs.
Please see http://godoc.org/github.com/go-playground/validator/v10 for detailed usage docs.
##### Examples:
- [Simple](https://github.com/go-playground/validator/blob/v9/_examples/simple/main.go)
- [Custom Field Types](https://github.com/go-playground/validator/blob/v9/_examples/custom/main.go)
- [Struct Level](https://github.com/go-playground/validator/blob/v9/_examples/struct-level/main.go)
- [Translations & Custom Errors](https://github.com/go-playground/validator/blob/v9/_examples/translations/main.go)
- [Simple](https://github.com/go-playground/validator/blob/master/_examples/simple/main.go)
- [Custom Field Types](https://github.com/go-playground/validator/blob/master/_examples/custom/main.go)
- [Struct Level](https://github.com/go-playground/validator/blob/master/_examples/struct-level/main.go)
- [Translations & Custom Errors](https://github.com/go-playground/validator/blob/master/_examples/translations/main.go)
- [Gin upgrade and/or override validator](https://github.com/go-playground/validator/tree/v9/_examples/gin-upgrading-overriding)
- [wash - an example application putting it all together](https://github.com/bluesuncorp/wash)

@ -3,7 +3,7 @@ package main
import (
"fmt"
"gopkg.in/go-playground/validator.v9"
"github.com/go-playground/validator/v10"
)
// MyStruct ..

@ -6,7 +6,7 @@ import (
"fmt"
"reflect"
"gopkg.in/go-playground/validator.v9"
"github.com/go-playground/validator/v10"
)
// DbBackedUser User struct

@ -3,7 +3,7 @@ package main
import (
"fmt"
"gopkg.in/go-playground/validator.v9"
"github.com/go-playground/validator/v10"
)
// Test ...

@ -5,7 +5,7 @@ import (
"sync"
"github.com/gin-gonic/gin/binding"
"gopkg.in/go-playground/validator.v9"
"github.com/go-playground/validator/v10"
)
type defaultValidator struct {

@ -3,7 +3,7 @@ package main
import (
"fmt"
"gopkg.in/go-playground/validator.v9"
"github.com/go-playground/validator/v10"
)
// User contains user information

@ -3,7 +3,7 @@ package main
import (
"fmt"
"gopkg.in/go-playground/validator.v9"
"github.com/go-playground/validator/v10"
)
// User contains user information

@ -5,8 +5,8 @@ import (
"github.com/go-playground/locales/en"
ut "github.com/go-playground/universal-translator"
"gopkg.in/go-playground/validator.v9"
en_translations "gopkg.in/go-playground/validator.v9/translations/en"
"github.com/go-playground/validator/v10"
en_translations "github.com/go-playground/validator/v10/translations/en"
)
// User contains user information

@ -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=

@ -4,7 +4,7 @@ import (
"reflect"
"strings"
"gopkg.in/go-playground/validator.v9"
"github.com/go-playground/validator/v10"
)
// NotBlank is the validation function for validating if the current field

@ -3,8 +3,8 @@ package validators
import (
"testing"
"gopkg.in/go-playground/validator.v9"
"gopkg.in/go-playground/assert.v1"
"github.com/go-playground/validator/v10"
"github.com/go-playground/assert/v2"
)
type test struct {

@ -10,7 +10,7 @@ import (
"github.com/go-playground/locales"
ut "github.com/go-playground/universal-translator"
"gopkg.in/go-playground/validator.v9"
"github.com/go-playground/validator/v10"
)
// RegisterDefaultTranslations registers a set of default translations

@ -6,8 +6,8 @@ import (
english "github.com/go-playground/locales/en"
ut "github.com/go-playground/universal-translator"
. "gopkg.in/go-playground/assert.v1"
"gopkg.in/go-playground/validator.v9"
. "github.com/go-playground/assert/v2"
"github.com/go-playground/validator/v10"
)
func TestTranslations(t *testing.T) {

@ -10,7 +10,7 @@ import (
"github.com/go-playground/locales"
ut "github.com/go-playground/universal-translator"
"gopkg.in/go-playground/validator.v9"
"github.com/go-playground/validator/v10"
)
// RegisterDefaultTranslations registers a set of default translations

@ -6,8 +6,8 @@ import (
french "github.com/go-playground/locales/fr"
ut "github.com/go-playground/universal-translator"
. "gopkg.in/go-playground/assert.v1"
"gopkg.in/go-playground/validator.v9"
. "github.com/go-playground/assert/v2"
"github.com/go-playground/validator/v10"
)
func TestTranslations(t *testing.T) {

@ -10,7 +10,7 @@ import (
"github.com/go-playground/locales"
ut "github.com/go-playground/universal-translator"
"gopkg.in/go-playground/validator.v9"
"github.com/go-playground/validator/v10"
)
// RegisterDefaultTranslations registers a set of default translations

@ -6,8 +6,8 @@ import (
indonesia "github.com/go-playground/locales/id"
ut "github.com/go-playground/universal-translator"
. "gopkg.in/go-playground/assert.v1"
"gopkg.in/go-playground/validator.v9"
. "github.com/go-playground/assert/v2"
"github.com/go-playground/validator/v10"
)
func TestTranslations(t *testing.T) {

@ -10,7 +10,7 @@ import (
"github.com/go-playground/locales"
ut "github.com/go-playground/universal-translator"
"gopkg.in/go-playground/validator.v9"
"github.com/go-playground/validator/v10"
)
// RegisterDefaultTranslations registers a set of default translations

@ -6,8 +6,8 @@ import (
ja_locale "github.com/go-playground/locales/ja"
ut "github.com/go-playground/universal-translator"
. "gopkg.in/go-playground/assert.v1"
"gopkg.in/go-playground/validator.v9"
. "github.com/go-playground/assert/v2"
"github.com/go-playground/validator/v10"
)
func TestTranslations(t *testing.T) {

@ -10,7 +10,7 @@ import (
"github.com/go-playground/locales"
ut "github.com/go-playground/universal-translator"
"gopkg.in/go-playground/validator.v9"
"github.com/go-playground/validator/v10"
)
// RegisterDefaultTranslations registers a set of default translations

@ -6,8 +6,8 @@ import (
english "github.com/go-playground/locales/en"
ut "github.com/go-playground/universal-translator"
. "gopkg.in/go-playground/assert.v1"
"gopkg.in/go-playground/validator.v9"
. "github.com/go-playground/assert/v2"
"github.com/go-playground/validator/v10"
)
func TestTranslations(t *testing.T) {

@ -10,7 +10,7 @@ import (
"github.com/go-playground/locales"
ut "github.com/go-playground/universal-translator"
"gopkg.in/go-playground/validator.v9"
"github.com/go-playground/validator/v10"
)
// RegisterDefaultTranslations registers a set of default translations

@ -6,8 +6,8 @@ import (
brazilian_portuguese "github.com/go-playground/locales/pt_BR"
ut "github.com/go-playground/universal-translator"
"gopkg.in/go-playground/validator.v9"
. "gopkg.in/go-playground/assert.v1"
"github.com/go-playground/validator/v10"
. "github.com/go-playground/assert/v2"
)
func TestTranslations(t *testing.T) {

@ -10,7 +10,7 @@ import (
"github.com/go-playground/locales"
ut "github.com/go-playground/universal-translator"
"gopkg.in/go-playground/validator.v9"
"github.com/go-playground/validator/v10"
)
// RegisterDefaultTranslations registers a set of default translations

@ -6,8 +6,8 @@ import (
turkish "github.com/go-playground/locales/tr"
ut "github.com/go-playground/universal-translator"
. "gopkg.in/go-playground/assert.v1"
"gopkg.in/go-playground/validator.v9"
. "github.com/go-playground/assert/v2"
"github.com/go-playground/validator/v10"
)
func TestTranslations(t *testing.T) {

@ -10,7 +10,7 @@ import (
"github.com/go-playground/locales"
ut "github.com/go-playground/universal-translator"
"gopkg.in/go-playground/validator.v9"
"github.com/go-playground/validator/v10"
)
// RegisterDefaultTranslations registers a set of default translations

@ -6,8 +6,8 @@ import (
zhongwen "github.com/go-playground/locales/zh"
ut "github.com/go-playground/universal-translator"
. "gopkg.in/go-playground/assert.v1"
"gopkg.in/go-playground/validator.v9"
. "github.com/go-playground/assert/v2"
"github.com/go-playground/validator/v10"
)
func TestTranslations(t *testing.T) {

@ -10,7 +10,7 @@ import (
"github.com/go-playground/locales"
ut "github.com/go-playground/universal-translator"
"gopkg.in/go-playground/validator.v9"
"github.com/go-playground/validator/v10"
)
// RegisterDefaultTranslations registers a set of default translations

@ -6,8 +6,8 @@ import (
zhongwen "github.com/go-playground/locales/zh_Hant_TW"
ut "github.com/go-playground/universal-translator"
. "gopkg.in/go-playground/assert.v1"
"gopkg.in/go-playground/validator.v9"
. "github.com/go-playground/assert/v2"
"github.com/go-playground/validator/v10"
)
func TestTranslations(t *testing.T) {

@ -18,7 +18,7 @@ import (
"github.com/go-playground/locales/fr"
"github.com/go-playground/locales/nl"
ut "github.com/go-playground/universal-translator"
. "gopkg.in/go-playground/assert.v1"
. "github.com/go-playground/assert/v2"
)
// NOTES:

Loading…
Cancel
Save