MCPcopy Create free account
hub / github.com/SwishHQ/spread / ValidateStruct

Function ValidateStruct

utils/validator.go:19–29  ·  view source on GitHub ↗

Function to validate struct and return errors in a map format how to use: err := ValidateStruct(&App{}) if err != nil { fmt.Println(err) }

(s interface{})

Source from the content-addressed store, hash-verified

17// fmt.Println(err)
18// }
19func ValidateStruct(s interface{}) map[string]string {
20 err := Validate.Struct(s)
21 if err != nil {
22 errors := make(map[string]string)
23 for _, e := range err.(validator.ValidationErrors) {
24 errors[e.Field()] = fmt.Sprintf("Invalid value for %s", e.Field())
25 }
26 return errors
27 }
28 return nil
29}
30
31// BindAndValidate binds the request body to the struct and validates it
32// how to use:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected