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

77
vendor/github.com/go-ozzo/ozzo-validation/length.go generated vendored Normal file
View file

@ -0,0 +1,77 @@
// 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 validation
import (
"errors"
"fmt"
"unicode/utf8"
)
// Length returns a validation rule that checks if a value's length is within the specified range.
// If max is 0, it means there is no upper bound for the length.
// This rule should only be used for validating strings, slices, maps, and arrays.
// An empty value is considered valid. Use the Required rule to make sure a value is not empty.
func Length(min, max int) *lengthRule {
message := "the value must be empty"
if min == 0 && max > 0 {
message = fmt.Sprintf("the length must be no more than %v", max)
} else if min > 0 && max == 0 {
message = fmt.Sprintf("the length must be no less than %v", min)
} else if min > 0 && max > 0 {
message = fmt.Sprintf("the length must be between %v and %v", min, max)
}
return &lengthRule{
min: min,
max: max,
message: message,
}
}
// RuneLength returns a validation rule that checks if a string's rune length is within the specified range.
// If max is 0, it means there is no upper bound for the length.
// This rule should only be used for validating strings, slices, maps, and arrays.
// An empty value is considered valid. Use the Required rule to make sure a value is not empty.
// If the value being validated is not a string, the rule works the same as Length.
func RuneLength(min, max int) *lengthRule {
r := Length(min, max)
r.rune = true
return r
}
type lengthRule struct {
min, max int
message string
rune bool
}
// Validate checks if the given value is valid or not.
func (v *lengthRule) Validate(value interface{}) error {
value, isNil := Indirect(value)
if isNil || IsEmpty(value) {
return nil
}
var (
l int
err error
)
if s, ok := value.(string); ok && v.rune {
l = utf8.RuneCountInString(s)
} else if l, err = LengthOfValue(value); err != nil {
return err
}
if v.min > 0 && l < v.min || v.max > 0 && l > v.max {
return errors.New(v.message)
}
return nil
}
// Error sets the error message for the rule.
func (v *lengthRule) Error(message string) *lengthRule {
v.message = message
return v
}