From d792c5a5789ecdfbe19eda6a94790b0fa8cfe2a9 Mon Sep 17 00:00:00 2001 From: joeybloggs Date: Wed, 2 Sep 2015 08:59:36 -0400 Subject: [PATCH] Add validation error info to DOC --- doc.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc.go b/doc.go index cc96f2d..843b00d 100644 --- a/doc.go +++ b/doc.go @@ -16,6 +16,16 @@ I needed to know the field and what validation failed so that I could provide an return "Translated string based on field" } +Validation functions return type error + +They return type error to avoid the issue discussed in the following, where err is always != nil: +http://stackoverflow.com/a/29138676/3158232 +https://github.com/bluesuncorp/validator/issues/134 + +validator only returns nil or ValidationErrors as type error; so in you code all you need to do +is check if the error returned is not nil, and if it's not type cast it to type ValidationErrors +like so err.(validator.ValidationErrors) + Custom Functions Custom functions can be added