// IntegerValidator converts the input to a integer with strconv.Atoi
// If input is empty we return nil instead of an integer so you can set a default on your side
329981
func IntegerValidator(input string) (interface{}, error) {
	if input == "" {
		return nil, nil
	}

	i, err := strconv.Atoi(input)
	if err != nil {
		return nil, err
	}

	return i, nil
}
663236
func EnumValidator(param string, v reflect.Value) (ValidationResult, error) {
	if param == "" {
		return 0, ErrInvalidConfigValue
	}

	params := strings.Split(param, "|")

	var enum func(v reflect.Value) (ValidationResult, error)
	enum = func(v reflect.Value) (ValidationResult, error) {
		if v.Kind() == reflect.Ptr {
			v = v.Elem()
		}
		switch v.Kind() {
		case reflect.String:
			val := v.String()
			if val == "" {
				// need empty checking? use req :)
				return ValidationOK, nil
			}
			for _, value := range params {
				if val == value {
					return ValidationOK, nil
				}
			}
			return ValidationNG, nil
		case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
			val := v.Int()
			for _, value := range params {
				value2, err := strconv.ParseInt(value, 10, 0)
				if err != nil {
					return 0, ErrInvalidConfigValue
				}
				if val == value2 {
					return ValidationOK, nil
				}
			}
			return ValidationNG, nil
		case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
			val := v.Uint()
			for _, value := range params {
				value2, err := strconv.ParseUint(value, 10, 0)
				if err != nil {
					return 0, ErrInvalidConfigValue
				}
				if val == value2 {
					return ValidationOK, nil
				}
			}
			return ValidationNG, nil
		case reflect.Array, reflect.Slice:
			for i := 0; i < v.Len(); i++ {
				e := v.Index(i)
				return enum(e)
			}
		default:
			return 0, ErrValidateUnsupportedType
		}

		return ValidationOK, nil
	}

	return enum(v)
}
795898
func (env *environ) ConstraintsValidator(ctx context.ProviderCallContext) (constraints.Validator, error) {
	validator := constraints.NewValidator()

	// conflicts

	// TODO(ericsnow) Are these correct?
	validator.RegisterConflicts(
		[]string{constraints.InstanceType},
		instanceTypeConstraints,
	)

	// unsupported

	validator.RegisterUnsupported(unsupportedConstraints)

	// vocab

	instTypeNames := make([]string, len(allInstanceTypes))
	for i, itype := range allInstanceTypes {
		instTypeNames[i] = itype.Name
	}
	validator.RegisterVocabulary(constraints.InstanceType, instTypeNames)

	validator.RegisterVocabulary(constraints.Container, []string{vtype})

	return validator, nil
}
469979
func Optional(v Validator) Validator {
	return func(args []string) int {
		if len(args) == 0 {
			return 0
		}
		return v(args)
	}
}
466949
func NewValidator() *Validator {
	v := &Validator{}
	v.SetTag("validate")
	v.SetValidationFunc("req", ReqValidator)
	v.SetValidationFunc("d", DefaultValidator)
	v.SetValidationFunc("min", MinValidator)
	v.SetValidationFunc("max", MaxValidator)
	v.SetValidationFunc("minLen", MinLenValidator)
	v.SetValidationFunc("maxLen", MaxLenValidator)
	v.SetValidationFunc("email", EmailValidator)
	v.SetValidationFunc("enum", EnumValidator)
	v.SetValidationFunc("regexp", RegExpValidator)
	return v
}
360982
func NewIntegerValue(value int) *Integer {
	returnValue := new(Integer)
	returnValue.value = value
	return returnValue
}
758560
func RecordValidator(ps peerstore.Peerstore) record.Validator {
	return record.NamespacedValidator{
		"pk":   record.PublicKeyValidator{},
		"ipns": ipns.Validator{KeyBook: ps},
	}
}
558521
func (s *Qualification) SetIntegerValue(v int64) *Qualification {
	s.IntegerValue = &v
	return s
}
1007764
func Validator(preValidators []PreValidator, postValidators []PostValidator) Rule {
	return &validatorRule{
		preValidators:  preValidators,
		postValidators: postValidators,
	}
}
170920
func AtoiWithDefault(s string, def int) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		return def
	}
	return i
}
1357616
func (c Conversation) Integer(name string) (int, error) {
	return c.match.Integer(name)
}
1265796
func Int32(val string) (int32, error) {
	i, err := strconv.ParseInt(val, 0, 32)
	if err != nil {
		return 0, err
	}
	return int32(i), nil
}
665085
func (m *Mux) RegisterValidator(name string, validator Validator) {
	if m.Validators == nil {
		m.Validators = make(map[string]Validator)
	}
	m.Validators[name] = validator
}
740907
func (e *environ) ConstraintsValidator(ctx context.ProviderCallContext) (constraints.Validator, error) {
	validator := constraints.NewValidator()
	validator.RegisterConflicts(
		[]string{constraints.InstanceType},
		[]string{constraints.Mem, constraints.Cores, constraints.CpuPower})
	validator.RegisterUnsupported(unsupportedConstraints)
	instanceTypes, err := e.supportedInstanceTypes(ctx)
	if err != nil {
		return nil, errors.Trace(err)
	}
	instTypeNames := make([]string, len(instanceTypes))
	for i, itype := range instanceTypes {
		instTypeNames[i] = itype.Name
	}
	validator.RegisterVocabulary(constraints.InstanceType, instTypeNames)
	return validator, nil
}
1089791
func (pkz privKeys) ToValidators(init, inc int64) *types.ValidatorSet {
	res := make([]*types.Validator, len(pkz))
	for i, k := range pkz {
		res[i] = types.NewValidator(k.PubKey(), init+int64(i)*inc)
	}
	return types.NewValidatorSet(res)
}
1265899
func MustParseInt(s string) (i int) {
	i, _ = strconv.Atoi(s)
	return
}
1097610
func RequiredValidator(input string) (interface{}, error) {
	if input == "" {
		return nil, fmt.Errorf("This option is required")
	}

	return input, nil
}