UserStructLevelValidation contains custom struct level validations that don't always make sense at the field validation level. For example, this function validates that either FirstName or LastName exist; could have done that with a custom field validation but then would have had to add it to both f
(sl validator.StructLevel)
| 165 | // hooks right into validator and you can combine with validation tags and still have a |
| 166 | // common error output format. |
| 167 | func UserStructLevelValidation(sl validator.StructLevel) { |
| 168 | |
| 169 | user := sl.Current().Interface().(User) |
| 170 | |
| 171 | if len(user.FirstName) == 0 && len(user.LastName) == 0 { |
| 172 | sl.ReportError(user.FirstName, "fname", "FirstName", "fnameorlname", "") |
| 173 | sl.ReportError(user.LastName, "lname", "LastName", "fnameorlname", "") |
| 174 | } |
| 175 | |
| 176 | // plus can do more, even with different tag than "fnameorlname" |
| 177 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…