Documentation ¶
Overview ¶
Package to parse a tag.
Tags are annotation with struct fields, that allow for some elegant solutions for different problems. Examples are validation and alike. This is an example on what that might look like:
type Example struct { AField string `tagName1:"tagValue1" tagName2:"tagValue2"` }
As the syntax is somewhat weird and the tag interface only supports a getter, this tag parser was written. It will use go's tag parser to retrieve the tag for a given prefix, parse the value, and return a map of strings to strings. Keys and values are separated by an equal sign '=', values might be quoted using single quotes "'", and key-value pairs are separated using whitespace.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
func Parse(field reflect.StructField, prefix string, customHander func(string) (string, string, error)) (result map[string]string, e error)
Parse tag with the given prefix of the given field. Return a map of strings to strings. If errors occur they are returned accordingly.
func ParseCustom ¶
func ParseCustom(field reflect.StructField, prefix string, customF CustomSplitter) (result map[string]string, e error)
Like Parse, but with a custom splitter used for tag values that don't have the form `key=value`.