MCPcopy Create free account
hub / github.com/StephanyBatista/EmailN / ValidateStruct

Function ValidateStruct

internal/internal-errors/validator.go:10–31  ·  view source on GitHub ↗
(obj interface{})

Source from the content-addressed store, hash-verified

8)
9
10func ValidateStruct(obj interface{}) error {
11 validate := validator.New()
12 err := validate.Struct(obj)
13 if err == nil {
14 return nil
15 }
16 validationErrors := err.(validator.ValidationErrors)
17 validationError := validationErrors[0]
18
19 field := strings.ToLower(validationError.StructField())
20 switch validationError.Tag() {
21 case "required":
22 return errors.New(field + " is required")
23 case "max":
24 return errors.New(field + " is required with max " + validationError.Param())
25 case "min":
26 return errors.New(field + " is required with min " + validationError.Param())
27 case "email":
28 return errors.New(field + " is invalid")
29 }
30 return nil
31}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected