This commit is contained in:
2024-11-22 12:09:50 +03:00
parent 80491ed643
commit 9ec34c6bfc
21 changed files with 57 additions and 156 deletions

View File

@@ -372,6 +372,13 @@ func urlValidartor(fl validator.FieldLevel) bool {
return err == nil
}
func chipsetValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
fieldValue = strings.ToLower(fieldValue)
return IsInSlice(fieldValue, chipsetValues)
}
// ValidateRAM checks if request contains RAM value that is positive integer divisible by divisibility passed.
// It is recommended to pass constants.RAM_DIVISIBILITY as divisility arguement
func ValidateRAM(r interfaces.RequestWithRAM, divisibility uint64) error {

View File

@@ -299,6 +299,12 @@ func errorMessage(fe validator.FieldError) string {
prefix,
fe.Field(),
joinValues(kvmx86NetTypeValues))
case "chipset":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(chipsetValues))
}
return fe.Error()

View File

@@ -256,5 +256,10 @@ func registerAllValidators(validate *validator.Validate) error {
return err
}
err = validate.RegisterValidation("chipset", chipsetValidator)
if err != nil {
return err
}
return nil
}

View File

@@ -62,6 +62,8 @@ var (
ioEventFDValues = []string{"on", "off", "selected by hypervisor"}
eventIDxValues = []string{"on", "off", "selected by hypervisor"}
chipsetValues = []string{"i440fx", "Q35"}
)
const (