You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We want to support some very basic templating features in error messages
returned by Validate() functions.
Specifically, within a Validate() method on a struct type, we want to support
field name normalization via the FieldNameFunc feature, to convert the field
name to it's JSON/YAML/Form tag.
This would allow a error message like:
only allowed ObjectType='book'
The ObjectType field name is the Go struct field name, if this object uses
JSON, the external name of the field in JSON might be object_type or objectType. So we want to be able to indicate in the error message that ObjectType is a field on the struct.
I think we could do this a few different ways. Assuming we the following struct:
We want to support some very basic templating features in error messages
returned by
Validate()
functions.Specifically, within a
Validate()
method on a struct type, we want to supportfield name normalization via the FieldNameFunc feature, to convert the field
name to it's JSON/YAML/Form tag.
This would allow a error message like:
The
ObjectType
field name is the Go struct field name, if this object usesJSON, the external name of the field in JSON might be
object_type
orobjectType
. So we want to be able to indicate in the error message thatObjectType
is a field on the struct.I think we could do this a few different ways. Assuming we the following struct:
We want the end result to be this:
We could use a custom syntax, something like one of these:
Or we could leverage the
text/template
package using a customfield
function:
Some of the field validation helpers mentioned in #4 could benefit from this
feature too.
The text was updated successfully, but these errors were encountered: