vendor dependencies with dep

This commit is contained in:
dhax 2017-09-25 20:20:52 +02:00
parent 93d8310491
commit 1384296a47
2712 changed files with 965742 additions and 0 deletions

138
vendor/github.com/go-ozzo/ozzo-validation/is/rules.go generated vendored Normal file
View file

@ -0,0 +1,138 @@
// Copyright 2016 Qiang Xue. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
// Package is provides a list of commonly used string validation rules.
package is
import (
"regexp"
"unicode"
"github.com/asaskevich/govalidator"
"github.com/go-ozzo/ozzo-validation"
)
var (
// Email validates if a string is an email or not.
Email = validation.NewStringRule(govalidator.IsEmail, "must be a valid email address")
// URL validates if a string is a valid URL
URL = validation.NewStringRule(govalidator.IsURL, "must be a valid URL")
// RequestURL validates if a string is a valid request URL
RequestURL = validation.NewStringRule(govalidator.IsRequestURL, "must be a valid request URL")
// RequestURI validates if a string is a valid request URI
RequestURI = validation.NewStringRule(govalidator.IsRequestURI, "must be a valid request URI")
// Alpha validates if a string contains English letters only (a-zA-Z)
Alpha = validation.NewStringRule(govalidator.IsAlpha, "must contain English letters only")
// Digit validates if a string contains digits only (0-9)
Digit = validation.NewStringRule(isDigit, "must contain digits only")
// Alphanumeric validates if a string contains English letters and digits only (a-zA-Z0-9)
Alphanumeric = validation.NewStringRule(govalidator.IsAlphanumeric, "must contain English letters and digits only")
// UTFLetter validates if a string contains unicode letters only
UTFLetter = validation.NewStringRule(govalidator.IsUTFLetter, "must contain unicode letter characters only")
// UTFDigit validates if a string contains unicode decimal digits only
UTFDigit = validation.NewStringRule(govalidator.IsUTFDigit, "must contain unicode decimal digits only")
// UTFLetterNumeric validates if a string contains unicode letters and numbers only
UTFLetterNumeric = validation.NewStringRule(govalidator.IsUTFLetterNumeric, "must contain unicode letters and numbers only")
// UTFNumeric validates if a string contains unicode number characters (category N) only
UTFNumeric = validation.NewStringRule(isUTFNumeric, "must contain unicode number characters only")
// LowerCase validates if a string contains lower case unicode letters only
LowerCase = validation.NewStringRule(govalidator.IsLowerCase, "must be in lower case")
// UpperCase validates if a string contains upper case unicode letters only
UpperCase = validation.NewStringRule(govalidator.IsUpperCase, "must be in upper case")
// Hexadecimal validates if a string is a valid hexadecimal number
Hexadecimal = validation.NewStringRule(govalidator.IsHexadecimal, "must be a valid hexadecimal number")
// HexColor validates if a string is a valid hexadecimal color code
HexColor = validation.NewStringRule(govalidator.IsHexcolor, "must be a valid hexadecimal color code")
// RGBColor validates if a string is a valid RGB color in the form of rgb(R, G, B)
RGBColor = validation.NewStringRule(govalidator.IsRGBcolor, "must be a valid RGB color code")
// Int validates if a string is a valid integer number
Int = validation.NewStringRule(govalidator.IsInt, "must be an integer number")
// Float validates if a string is a floating point number
Float = validation.NewStringRule(govalidator.IsFloat, "must be a floating point number")
// UUIDv3 validates if a string is a valid version 3 UUID
UUIDv3 = validation.NewStringRule(govalidator.IsUUIDv3, "must be a valid UUID v3")
// UUIDv4 validates if a string is a valid version 4 UUID
UUIDv4 = validation.NewStringRule(govalidator.IsUUIDv4, "must be a valid UUID v4")
// UUIDv5 validates if a string is a valid version 5 UUID
UUIDv5 = validation.NewStringRule(govalidator.IsUUIDv5, "must be a valid UUID v5")
// UUID validates if a string is a valid UUID
UUID = validation.NewStringRule(govalidator.IsUUID, "must be a valid UUID")
// CreditCard validates if a string is a valid credit card number
CreditCard = validation.NewStringRule(govalidator.IsCreditCard, "must be a valid credit card number")
// ISBN10 validates if a string is an ISBN version 10
ISBN10 = validation.NewStringRule(govalidator.IsISBN10, "must be a valid ISBN-10")
// ISBN13 validates if a string is an ISBN version 13
ISBN13 = validation.NewStringRule(govalidator.IsISBN13, "must be a valid ISBN-13")
// ISBN validates if a string is an ISBN (either version 10 or 13)
ISBN = validation.NewStringRule(isISBN, "must be a valid ISBN")
// JSON validates if a string is in valid JSON format
JSON = validation.NewStringRule(govalidator.IsJSON, "must be in valid JSON format")
// ASCII validates if a string contains ASCII characters only
ASCII = validation.NewStringRule(govalidator.IsASCII, "must contain ASCII characters only")
// PrintableASCII validates if a string contains printable ASCII characters only
PrintableASCII = validation.NewStringRule(govalidator.IsPrintableASCII, "must contain printable ASCII characters only")
// Multibyte validates if a string contains multibyte characters
Multibyte = validation.NewStringRule(govalidator.IsMultibyte, "must contain multibyte characters")
// FullWidth validates if a string contains full-width characters
FullWidth = validation.NewStringRule(govalidator.IsFullWidth, "must contain full-width characters")
// HalfWidth validates if a string contains half-width characters
HalfWidth = validation.NewStringRule(govalidator.IsHalfWidth, "must contain half-width characters")
// VariableWidth validates if a string contains both full-width and half-width characters
VariableWidth = validation.NewStringRule(govalidator.IsVariableWidth, "must contain both full-width and half-width characters")
// Base64 validates if a string is encoded in Base64
Base64 = validation.NewStringRule(govalidator.IsBase64, "must be encoded in Base64")
// DataURI validates if a string is a valid base64-encoded data URI
DataURI = validation.NewStringRule(govalidator.IsDataURI, "must be a Base64-encoded data URI")
// CountryCode2 validates if a string is a valid ISO3166 Alpha 2 country code
CountryCode2 = validation.NewStringRule(govalidator.IsISO3166Alpha2, "must be a valid two-letter country code")
// CountryCode3 validates if a string is a valid ISO3166 Alpha 3 country code
CountryCode3 = validation.NewStringRule(govalidator.IsISO3166Alpha3, "must be a valid three-letter country code")
// DialString validates if a string is a valid dial string that can be passed to Dial()
DialString = validation.NewStringRule(govalidator.IsDialString, "must be a valid dial string")
// MAC validates if a string is a MAC address
MAC = validation.NewStringRule(govalidator.IsMAC, "must be a valid MAC address")
// IP validates if a string is a valid IP address (either version 4 or 6)
IP = validation.NewStringRule(govalidator.IsIP, "must be a valid IP address")
// IPv4 validates if a string is a valid version 4 IP address
IPv4 = validation.NewStringRule(govalidator.IsIPv4, "must be a valid IPv4 address")
// IPv6 validates if a string is a valid version 6 IP address
IPv6 = validation.NewStringRule(govalidator.IsIPv6, "must be a valid IPv6 address")
// DNSName validates if a string is valid DNS name
DNSName = validation.NewStringRule(govalidator.IsDNSName, "must be a valid DNS name")
// Host validates if a string is a valid IP (both v4 and v6) or a valid DNS name
Host = validation.NewStringRule(govalidator.IsHost, "must be a valid IP address or DNS name")
// Port validates if a string is a valid port number
Port = validation.NewStringRule(govalidator.IsPort, "must be a valid port number")
// MongoID validates if a string is a valid Mongo ID
MongoID = validation.NewStringRule(govalidator.IsMongoID, "must be a valid hex-encoded MongoDB ObjectId")
// Latitude validates if a string is a valid latitude
Latitude = validation.NewStringRule(govalidator.IsLatitude, "must be a valid latitude")
// Longitude validates if a string is a valid longitude
Longitude = validation.NewStringRule(govalidator.IsLongitude, "must be a valid longitude")
// SSN validates if a string is a social security number (SSN)
SSN = validation.NewStringRule(govalidator.IsSSN, "must be a valid social security number")
// Semver validates if a string is a valid semantic version
Semver = validation.NewStringRule(govalidator.IsSemver, "must be a valid semantic version")
)
var (
reDigit = regexp.MustCompile("^[0-9]+$")
)
func isISBN(value string) bool {
return govalidator.IsISBN(value, 10) || govalidator.IsISBN(value, 13)
}
func isDigit(value string) bool {
return reDigit.MatchString(value)
}
func isUTFNumeric(value string) bool {
for _, c := range value {
if unicode.IsNumber(c) == false {
return false
}
}
return true
}

View file

@ -0,0 +1,94 @@
// Copyright 2016 Qiang Xue. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package is
import (
"testing"
"github.com/go-ozzo/ozzo-validation"
"github.com/stretchr/testify/assert"
)
func TestAll(t *testing.T) {
tests := []struct {
tag string
rule validation.Rule
valid, invalid string
err string
}{
{"Email", Email, "test@example.com", "example.com", "must be a valid email address"},
{"URL", URL, "http://example.com", "examplecom", "must be a valid URL"},
{"RequestURL", RequestURL, "http://example.com", "examplecom", "must be a valid request URL"},
{"RequestURI", RequestURI, "http://example.com", "examplecom", "must be a valid request URI"},
{"Alpha", Alpha, "abcd", "ab12", "must contain English letters only"},
{"Digit", Digit, "123", "12ab", "must contain digits only"},
{"Alphanumeric", Alphanumeric, "abc123", "abc.123", "must contain English letters and digits only"},
{"UTFLetter", UTFLetter, "", "", "must contain unicode letter characters only"},
{"UTFDigit", UTFDigit, "", "", "must contain unicode decimal digits only"},
{"UTFNumeric", UTFNumeric, "", ".", "must contain unicode number characters only"},
{"UTFLetterNumeric", UTFLetterNumeric, "", ".", "must contain unicode letters and numbers only"},
{"LowerCase", LowerCase, "c", "A", "must be in lower case"},
{"UpperCase", UpperCase, "ABC", "AB", "must be in upper case"},
{"IP", IP, "74.125.19.99", "74.125.19.999", "must be a valid IP address"},
{"IPv4", IPv4, "74.125.19.99", "2001:4860:0:2001::68", "must be a valid IPv4 address"},
{"IPv6", IPv6, "2001:4860:0:2001::68", "74.125.19.99", "must be a valid IPv6 address"},
{"MAC", MAC, "0123.4567.89ab", "74.125.19.99", "must be a valid MAC address"},
{"DNSName", DNSName, "example.com", "abc%", "must be a valid DNS name"},
{"Host", Host, "example.com", "abc%", "must be a valid IP address or DNS name"},
{"Port", Port, "123", "99999", "must be a valid port number"},
{"Latitude", Latitude, "23.123", "100", "must be a valid latitude"},
{"Longitude", Longitude, "123.123", "abc", "must be a valid longitude"},
{"SSN", SSN, "100-00-1000", "100-0001000", "must be a valid social security number"},
{"Semver", Semver, "1.0.0", "1.0.0.0", "must be a valid semantic version"},
{"ISBN", ISBN, "1-61729-085-8", "1-61729-085-81", "must be a valid ISBN"},
{"ISBN10", ISBN10, "1-61729-085-8", "1-61729-085-81", "must be a valid ISBN-10"},
{"ISBN13", ISBN13, "978-4-87311-368-5", "978-4-87311-368-a", "must be a valid ISBN-13"},
{"UUID", UUID, "a987fbc9-4bed-3078-cf07-9141ba07c9f1", "a987fbc9-4bed-3078-cf07-9141ba07c9f3a", "must be a valid UUID"},
{"UUIDv3", UUIDv3, "b987fbc9-4bed-3078-cf07-9141ba07c9f3", "b987fbc9-4bed-4078-cf07-9141ba07c9f3", "must be a valid UUID v3"},
{"UUIDv4", UUIDv4, "57b73598-8764-4ad0-a76a-679bb6640eb1", "b987fbc9-4bed-3078-cf07-9141ba07c9f3", "must be a valid UUID v4"},
{"UUIDv5", UUIDv5, "987fbc97-4bed-5078-af07-9141ba07c9f3", "b987fbc9-4bed-3078-cf07-9141ba07c9f3", "must be a valid UUID v5"},
{"MongoID", MongoID, "507f1f77bcf86cd799439011", "507f1f77bcf86cd79943901", "must be a valid hex-encoded MongoDB ObjectId"},
{"CreditCard", CreditCard, "375556917985515", "375556917985516", "must be a valid credit card number"},
{"JSON", JSON, "[1, 2]", "[1, 2,]", "must be in valid JSON format"},
{"ASCII", ASCII, "abc", "abc", "must contain ASCII characters only"},
{"PrintableASCII", PrintableASCII, "abc", "abc", "must contain printable ASCII characters only"},
{"CountryCode2", CountryCode2, "US", "XY", "must be a valid two-letter country code"},
{"CountryCode3", CountryCode3, "USA", "XYZ", "must be a valid three-letter country code"},
{"DialString", DialString, "localhost.local:1", "localhost.loc:100000", "must be a valid dial string"},
{"DataURI", DataURI, "data:image/png;base64,TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4=", "image/gif;base64,U3VzcGVuZGlzc2UgbGVjdHVzIGxlbw==", "must be a Base64-encoded data URI"},
{"Base64", Base64, "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4=", "image", "must be encoded in Base64"},
{"Multibyte", Multibyte, "", "abc", "must contain multibyte characters"},
{"FullWidth", FullWidth, "3ー0", "abc", "must contain full-width characters"},
{"HalfWidth", HalfWidth, "abc123い", "", "must contain half-width characters"},
{"VariableWidth", VariableWidth, "123", "abc", "must contain both full-width and half-width characters"},
{"Hexadecimal", Hexadecimal, "FEF", "FTF", "must be a valid hexadecimal number"},
{"HexColor", HexColor, "F00", "FTF", "must be a valid hexadecimal color code"},
{"RGBColor", RGBColor, "rgb(100, 200, 1)", "abc", "must be a valid RGB color code"},
{"Int", Int, "100", "1.1", "must be an integer number"},
{"Float", Float, "1.1", "a.1", "must be a floating point number"},
{"VariableWidth", VariableWidth, "", "", ""},
}
for _, test := range tests {
err := test.rule.Validate("")
assert.Nil(t, err, test.tag)
err = test.rule.Validate(test.valid)
assert.Nil(t, err, test.tag)
err = test.rule.Validate(&test.valid)
assert.Nil(t, err, test.tag)
err = test.rule.Validate(test.invalid)
assertError(t, test.err, err, test.tag)
err = test.rule.Validate(&test.invalid)
assertError(t, test.err, err, test.tag)
}
}
func assertError(t *testing.T, expected string, err error, tag string) {
if expected == "" {
assert.Nil(t, err, tag)
} else if assert.NotNil(t, err, tag) {
assert.Equal(t, expected, err.Error(), tag)
}
}