Exemplo n.º 1
0
func validateInvalidFields(new interface{}, fldPath *field.Path, fields []string) field.ErrorList {
	allErrs := field.ErrorList{}

	news := structs.New(new)

	for _, f := range fields {

		// ommitting immutable fields is OK
		if news.Field(f).IsZero() {
			continue
		}

		allErrs = append(allErrs, field.Forbidden(fldPath.Child(f), fmt.Sprintf("%s updates must not supply %s", fldPath.String(), news.Field(f).Name())))
	}

	return allErrs
}
Exemplo n.º 2
0
func validateImmutibleFields(new, old interface{}, fldPath *field.Path, fields []string) field.ErrorList {
	allErrs := field.ErrorList{}

	olds := structs.New(old)
	news := structs.New(new)

	for _, f := range fields {

		// ommitting immutable fields is OK
		if news.Field(f).IsZero() {
			continue
		}

		if !reflect.DeepEqual(news.Field(f).Value(), olds.Field(f).Value()) {
			allErrs = append(allErrs, field.Forbidden(fldPath.Child(f), fmt.Sprintf("%s updates must not change %s", fldPath.String(), news.Field(f).Name())))
		}
	}

	return allErrs
}