Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var CheckTCPHighPort = models.Validator{ Name: "Check if TCP port is high (between 1024 and 65535)", Func: func(val interface{}) error { var intVal int var err error var ok bool intVal, ok = val.(int) if !ok { stringValue, ok := val.(string) intVal, err = strconv.Atoi(stringValue) if !ok && err != nil { return fmt.Errorf("expected an int") } } if intVal >= 1024 && intVal <= 65535 { return nil } return fmt.Errorf("value (%d) is not a TCP high port ", intVal) }, }
CheckTCPHighPort validate that the port number is a high port
View Source
var StringNotEmpty = models.Validator{ Name: "String not empty", Func: func(input interface{}) error { stringVal, ok := input.(string) if !ok { return fmt.Errorf("expected a string") } if strings.TrimSpace(stringVal) == "" { return fmt.Errorf("empty value is not allowed") } return nil }, }
StringNotEmpty validate if a string value is not empty
View Source
var URLValidator = models.Validator{ Name: "Url Validator", Func: func(val interface{}) error { valString, ok := val.(string) if !ok { return fmt.Errorf("'%v' is not a even a string, can't be an url", val) } _, err := url.ParseRequestURI(valString) if err != nil { return fmt.Errorf("failed to parse %q as an url", valString) } return nil }, }
URLValidator validate that string provided is an url
Functions ¶
func AuthorizedValues ¶
func AuthorizedValues[T comparable](authorizedValues ...T) models.Validator
Return a Validator that check if the value received in the validation process is contained in the array of authorized values.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.