You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
decort-golang-sdk/internal/validators/messages.go

377 lines
9.0 KiB

package validators
import (
"fmt"
"strings"
"github.com/go-playground/validator/v10"
)
func errorMessage(fe validator.FieldError) string {
prefix := "validation-error:"
switch fe.Tag() {
3 years ago
// Common Validators
case "required":
return fmt.Sprintf("%s %s is required", prefix, fe.Field())
case "gt":
return fmt.Sprintf("%s %s can't be less or equal to zero", prefix, fe.Field())
case "min":
return fmt.Sprintf("%s %s: not enough elements", prefix, fe.Field())
case "max":
return fmt.Sprintf("%s %s: too many elements", prefix, fe.Field())
case "url":
return fmt.Sprintf("%s %s: unexpected URL format", prefix, fe.Field())
case "email":
return fmt.Sprintf("%s %s: unexpected E-Mail format", prefix, fe.Field())
1 year ago
case "isBool":
return fmt.Sprintf("%s %s: must be bool type", prefix, fe.Field())
3 years ago
case "accessType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
3 years ago
joinValues(accessTypeValues))
3 years ago
case "resTypes":
return fmt.Sprintf("%s %s can contain only the following values: %s",
prefix,
fe.Field(),
joinValues(resTypesValues))
case "proto":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(protoValues))
7 months ago
// apiGroup Validators
case "apiGroup":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(apiGroupValues))
3 years ago
// Account Validators
case "accountCUType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
3 years ago
joinValues(accountCUTypeValues))
3 years ago
// BService Validators
case "bserviceMode":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(bserviceModeValues))
// Compute Validators
case "computeTopology":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(computeTopologyValues))
case "computePolicy":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(computePolicyValues))
case "computeMode":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(computeModeValues))
case "computeDiskType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(computeDiskTypeValues))
1 year ago
case "mtu":
return fmt.Sprint(prefix, fe.Field(), "must be ", mtuMin, "-", mtuMax)
9 months ago
case "preferredCPU":
return fmt.Sprint(prefix, fe.Field(), "must be equal to or greater than", -1)
1 year ago
case "computex86NetType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
1 year ago
joinValues(computex86NetTypeValues))
1 year ago
case "computeNetType":
1 year ago
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
1 year ago
joinValues(computeNetTypeValues))
1 year ago
3 years ago
case "computeOrder":
return fmt.Sprintf("%s %s can contain only the following values: %s",
prefix,
fe.Field(),
joinValues(computeOrderValues))
case "computeDataDisks":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
3 years ago
joinValues(computeDataDisksValues))
// Disk Validators
case "diskType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(diskTypeValues))
// Flipgroup Validators
case "flipgroupClientType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(flipgroupClientTypeValues))
2 years ago
// k8s Validators
case "workerGroupName":
return fmt.Sprintf("%s %s must be more 3 symbol",
prefix,
fe.Field())
4 days ago
// KVM_X86 Mass create validators
case "massCreateNetType":
3 years ago
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
4 days ago
joinValues(massCreateNetTypeValues))
3 years ago
// LB Validators
case "lbAlgorithm":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(lbAlgorithmValues))
// RG Validators
case "rgDefNet":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(rgDefNetValues))
case "rgNetType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(rgNetTypeValues))
// ViNS Validators
case "vinsType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(vinsTypeValues))
// Image Validators
3 years ago
case "imageBootType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(imageBootTypeValues))
case "imageType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(imageTypeValues))
case "imageArchitecture":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(imageArchitectureValues))
3 years ago
// SEP Validators
case "sepFieldType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(sepFieldTypeValues))
3 years ago
// HWPath Validators
3 years ago
case "hwPath":
return fmt.Sprintf("%s %s must be in format 0000:1f:2b.0",
prefix,
fe.Field())
3 years ago
// Network plugin Validators
case "networkPlugin":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(networkPluginValues))
case "networkPlugins":
return fmt.Sprintf("%s %s must contain only the following: %s",
prefix,
fe.Field(),
joinValues(networkPluginValues))
case "strict_loose":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(strictLooseValues))
case "interfaceState":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(interfaceStateValues))
2 years ago
1 year ago
case "interfaceTXModel":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(txModelValues))
case "interfaceIOEventFD":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(ioEventFDValues))
case "interfaceEventIDx":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(eventIDxValues))
2 years ago
case "sortBy":
return fmt.Sprintf("%s %s must be in format +|-(field)",
prefix,
fe.Field())
case "action":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(actionValues))
case "vmaction":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(vmActionValues))
case "computeFeatures":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(computeFeaturesValues))
case "networkInterfaceNaming":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(networkInterfaceNamingValues))
1 year ago
case "numaAffinity":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(numaAffinityValues))
case "kvmx86NetType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(kvmx86NetTypeValues))
1 year ago
case "chipset":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(chipsetValues))
7 months ago
case "loaderType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(loaderTypeValues))
case "language":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(languageValues))
case "sepType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(sepTypeValues))
4 months ago
// user validators
case "userProvider":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(userProviders))
3 months ago
// security group validators
case "securityGroupDirection":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(securityGroupDirectionValues))
case "securityGroupEthertype":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(securityGroupEthertypeValues))
case "securityGroupProtocol":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(securityGroupProtocolValues))
4 months ago
// trunk tags validator
case "trunkTags":
return fmt.Sprintf("%s %s must be in range from 1 to 4095",
prefix,
fe.Field())
4 days ago
// addressPoolNetTypeValidator validator
case "addressPoolNetTypeValidator":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(addressPoolNetTypeValues))
4 months ago
case "device":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(deviceValues))
4 days ago
case "ipTypes":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(ipTypeValues))
}
return fe.Error()
}
func joinValues(values []string) string {
return strings.Join(values, ", ")
}