On Sat, Dec 14, 2013 at 8:04 AM, Matthew Holt <
matthe...@gmail.com> wrote:
>
> I'm thinking of something similar to accessing map keys:
>
> value, ok := someMap[key]
>
> Where `ok` is true or false, depending on if the key exists in the map. This
> is tremendously helpful.
>
> Similarly, I think it would be really convenient to know if a struct field
> tag exists, even if its value is "". I'm talking about this function:
>
http://golang.org/pkg/reflect/#StructTag.Get
>
> For instance, to mark a field as required for Martini, you have a field tag
> like this:
>
> type BlogPost struct {
> Title string `form:"title" json:"title" required`
>
> Notice "required" is tacked on at the end. This doesn't break the existing
> implementation of the tag parser, but it would be nice to know if the
> "required" tag exists, even if its value is empty string "":
>
> tagValue, ok := structField.Get("required");
>
> I realize this is not necessarily backward-compatible, so what about a new
> function on StructField like .Tag() or .Has() or something?
I don't see a persuasive reason for this. StructTag.Get is for the
. You
are describing a slightly different convention. You can write a