parent
abc7b2679c
commit
cf044b0e2d
validator
|
@ -1,41 +0,0 @@
|
|||
package validator
|
||||
|
||||
import (
|
||||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
type ErrorResponse struct {
|
||||
FailedField string
|
||||
Tag string
|
||||
Value string
|
||||
}
|
||||
|
||||
var Validate = validator.New()
|
||||
|
||||
func ValidateStruct(event interface{}) []*ErrorResponse {
|
||||
var errors []*ErrorResponse
|
||||
err := Validate.Struct(event)
|
||||
if err != nil {
|
||||
for _, err := range err.(validator.ValidationErrors) {
|
||||
var element ErrorResponse
|
||||
element.FailedField = err.StructNamespace()
|
||||
element.Tag = err.Tag()
|
||||
element.Value = err.Param()
|
||||
errors = append(errors, &element)
|
||||
}
|
||||
}
|
||||
return errors
|
||||
}
|
||||
|
||||
func validateNumericString(fl validator.FieldLevel) bool {
|
||||
str := fl.Field().String()
|
||||
return strings.TrimSpace(str) != "" && regexp.MustCompile(`^[0-9]+$`).MatchString(str)
|
||||
}
|
||||
|
||||
func test() {
|
||||
log.Println("test")
|
||||
}
|
Loading…
Reference in New Issue