// validate validates the values in the specified map using the Validator
// function. If the Validator function is not set, this function returns true
545203
func (f *CustomUplinkFunctions) validate(fields map[string]interface{}, port uint8) (bool, error) {
	if f.Validator == "" {
		return true, nil
	}

	env := map[string]interface{}{
		"fields": fields,
		"port":   port,
	}
	code := fmt.Sprintf(`
		%s;
		Validator(fields, port)
	`, f.Validator)

	value, err := functions.RunCode("Validator", code, env, timeOut, f.Logger)
	if err != nil {
		return false, err
	}

	if value, ok := value.(bool); ok {
		return value, nil
	}

	return false, errors.NewErrInvalidArgument("Validator", "does not return a boolean")
}
604290
func (t *JSONToken) Validate(validators ...Validator) error {
	var err error
	if len(validators) == 0 {
		validators = append(validators, ValidAt(time.Now()))
	}
	for _, validator := range validators {
		if err = validator(t); err != nil {
			return err
		}
	}
	return nil
}
1082274
func (m *BPFMapList) Validate(formats strfmt.Registry) error {
	var res []error

	if err := m.validateMaps(formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}
1106738
func (bc *BooleanConstraint) Validate(v interface{}) error {
	rv := reflect.ValueOf(v)
	switch rv.Kind() {
	case reflect.Bool:
	default:
		return errors.New("value is not a boolean")
	}
	return nil
}
752599
func (vl *Validator) Validate(v interface{}) error {
	return vl.validateStruct(reflect.ValueOf(v))
}
759329
func (*NullSchema) Validate(v reflect.Value) bool {
	// Check if the value is something that can be null
	switch v.Kind() {
	case reflect.Interface:
		return v.IsNil()
	case reflect.Array:
		return v.Cap() == 0
	case reflect.Slice:
		return v.IsNil() || v.Cap() == 0
	case reflect.Map:
		return len(v.MapKeys()) == 0
	case reflect.String:
		return len(v.String()) == 0
	case reflect.Float32:
		// Should NaN floats be treated as null?
		return math.IsNaN(v.Float())
	case reflect.Float64:
		// Should NaN floats be treated as null?
		return math.IsNaN(v.Float())
	case reflect.Ptr:
		return v.IsNil()
	case reflect.Invalid:
		return true
	}

	// Nothing else in particular, so this should not validate?
	return false
}
950661
func (m *Buffer) Validate() error {
	if m == nil {
		return nil
	}

	if wrapper := m.GetMaxRequestBytes(); wrapper != nil {

		if wrapper.GetValue() <= 0 {
			return BufferValidationError{
				field:  "MaxRequestBytes",
				reason: "value must be greater than 0",
			}
		}

	}

	return nil
}
87078
func (s *UnionSchema) Validate(v reflect.Value) bool {
	v = dereference(v)
	for i := range s.Types {
		if t := s.Types[i]; t.Validate(v) {
			return true
		}
	}

	return false
}
1253174
func (a AnnotationsMap) Validate(_ interface{}) error {
	countReserved := 0
	for key, value := range a {
		// Make sure the key is a valid key
		if err := AnnotationKey(key).Validate(nil); err != nil {
			return errors.Errorf("Key '%s' is not a valid annotation key", key)
		}
		// Make sure that, if the key is reserved, it is validated
		if strings.HasPrefix(key, AnnotationReservedKeyPrefix) {
			found := false
			for _, reservedKey := range AnnotationKnownReservedKeys {
				if reservedKey == key {
					found = true
				}
			}
			if !found {
				return errors.Errorf("Key '%s' is not an accepted reserved key", key)
			}
			countReserved++
		}

		// Make sure every value is a valid value
		for _, subvalue := range value {
			if err := AnnotationValue(subvalue).Validate(nil); err != nil {
				return errors.Errorf("Value '%s' is not a valid annotation value", subvalue)
			}
		}
	}

	// Finally, make sure we didn't overflow the mx number of reserved keys
	if countReserved > AnnotationMaxReservedKeys {
		return errors.New("Annotation has more than 20 annotation keys")
	}
	return nil
}
1081313
func (v *MatchRule) Validate(value interface{}) error {
	value, isNil := Indirect(value)
	if isNil {
		return nil
	}

	isString, str, isBytes, bs := StringOrBytes(value)
	if isString && (str == "" || v.re.MatchString(str)) {
		return nil
	} else if isBytes && (len(bs) == 0 || v.re.Match(bs)) {
		return nil
	}
	return errors.New(v.message)
}
1043783
func (v *StringRule) Validate(value interface{}) error {
	value, isNil := Indirect(value)
	if isNil || IsEmpty(value) {
		return nil
	}

	str, err := EnsureString(value)
	if err != nil {
		return err
	}

	if v.validate(str) {
		return nil
	}
	return errors.New(v.message)
}
1097301
func (c *GroupsCreateCall) Validate(validate bool) *GroupsCreateCall {
	c.validate = validate
	return c
}
1187577
func (e Error) Validate(v interface{}) error {
	if e.Message == "" {
		return fmt.Errorf("invalid error message %q", e.Message)
	}

	if e.Code <= 0 {
		return fmt.Errorf("invalid error code %d", e.Code)
	}

	return nil
}
19231
func (o *IntOptions) Validate(n models.ConfigurationMap) error {
	o.optsMU.RLock()
	defer o.optsMU.RUnlock()
	for k, v := range n {
		_, newVal, err := ParseKeyValue(o.Library, k, v)
		if err != nil {
			return err
		}

		// Ignore validation if value is identical
		if oldVal, ok := o.Opts[k]; ok && oldVal == newVal {
			continue
		}

		if err := o.Library.Validate(k, v); err != nil {
			return err
		}
	}

	return nil
}
1347024
func (v *validator) Validate(cons Value) ([]string, error) {
	unsupported := v.checkUnsupported(cons)
	if err := v.checkConflicts(cons); err != nil {
		return unsupported, err
	}
	if err := v.checkValidValues(cons); err != nil {
		return unsupported, err
	}
	return unsupported, nil
}
176890
func (t *Terraform) Validate() []error {
	var errs []error

	if raw := t.RequiredVersion; raw != "" {
		// Check that the value has no interpolations
		rc, err := NewRawConfig(map[string]interface{}{
			"root": raw,
		})
		if err != nil {
			errs = append(errs, fmt.Errorf(
				"terraform.required_version: %s", err))
		} else if len(rc.Interpolations) > 0 {
			errs = append(errs, fmt.Errorf(
				"terraform.required_version: cannot contain interpolations"))
		} else {
			// Check it is valid
			_, err := version.NewConstraint(raw)
			if err != nil {
				errs = append(errs, fmt.Errorf(
					"terraform.required_version: invalid syntax: %s", err))
			}
		}
	}

	if t.Backend != nil {
		errs = append(errs, t.Backend.Validate()...)
	}

	return errs
}
693906
func (v *Validator) Validate(h http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if err := v.ValidRequest(r); err != nil {
			http.Error(w, "", http.StatusUnauthorized)
			return
		}
		h.ServeHTTP(w, r)
	})
}