From 38fdfa198f41879eb055333fbc1da588804f89ff Mon Sep 17 00:00:00 2001 From: qiangxue Date: Wed, 4 Dec 2019 11:50:51 -0500 Subject: [PATCH] Fixes #81: Added doc to clarify the potential misusage --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 37ae8b1..ad219bb 100644 --- a/README.md +++ b/README.md @@ -225,7 +225,12 @@ When `validation.Validate` is used to validate a validatable value, if it does n given validation rules, it will further call the value's `Validate()` method. Similarly, when `validation.ValidateStruct` is validating a struct field whose type is validatable, it will call -the field's `Validate` method after it passes the listed rules. +the field's `Validate` method after it passes the listed rules. + +> Note: When implementing `validation.Validatable`, do not call `validation.Validate()` to validate the value in its +> original type because this will cause infinite loops. For example, if you define a new type `MyString` as `string` +> and implement `validation.Validatable` for `MyString`, within the `Validate()` function you should cast the value +> to `string` first before calling `validation.Validate()` to validate it. In the following example, the `Address` field of `Customer` is validatable because `Address` implements `validation.Validatable`. Therefore, when validating a `Customer` struct with `validation.ValidateStruct`,