22 lines
664 B
Go
22 lines
664 B
Go
package validation
|
|
|
|
import (
|
|
"users_management/m/model/entity"
|
|
"github.com/go-playground/validator/v10"
|
|
)
|
|
|
|
// RegisterPortValidators registers port-related validation rules
|
|
func RegisterPortValidators(validate *validator.Validate) {
|
|
validate.RegisterValidation("portstatus", validatePortStatus)
|
|
}
|
|
|
|
// validatePortStatus checks if the value is a valid PortStatus
|
|
func validatePortStatus(fl validator.FieldLevel) bool {
|
|
value := fl.Field().String()
|
|
switch entity.PortStatus(value) {
|
|
case entity.PortStatusOn, entity.PortStatusOff, entity.PortStatusDyingGasp, entity.PortStatusLOS:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
} |