Documentation
¶
Overview ¶
Example ¶
package main
import (
"fmt"
"reflect"
"github.com/alfatraining/structtag"
)
func main() {
type Example struct {
Field string `json:"foo,omitempty" xml:"bar"`
}
// Get the struct tag from the field
tag := reflect.TypeOf(Example{}).Field(0).Tag
// Parse the tag using structtag
tags, err := structtag.Parse(string(tag))
if err != nil {
panic(err)
}
// Iterate over all tags
for _, t := range tags.Tags() {
fmt.Printf("Key: %s, Value: %v\n", t.Key, t.Value)
}
}
Output: Key: json, Value: foo,omitempty Key: xml, Value: bar
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Tag ¶
type Tag struct {
// Key is the tag key, such as json, xml, etc.
// i.e: `json:"foo,omitempty". Here key is: "json"
Key string
// Value is the value stored for this tag key.
// i.e.: `json:"foo,omitempty". Here the value is: "foo,omitempty".
Value string
}
Tag defines a single struct's string literal tag
type Tags ¶
type Tags struct {
// contains filtered or unexported fields
}
Tags represent a set of tags from a single struct field
Click to show internal directories.
Click to hide internal directories.