structtag:解析和修改Go struct字段标签
结构标签
structtag提供了一种解析和处理struct tag Go字段的方法。 它被之类的工具使用。 有关更多示例,请签。
安装
go get github.com/fatih/structtag
例
package main
import (
"fmt"
"reflect"
"sort"
"github.com/fatih/structtag"
)
func main () {
type t struct {
t string `json:"foo,omitempty,string" xml:"foo"`
}
// get field tag
tag := reflect . TypeOf ( t {}). Field ( 0 ). Tag
// ... and start using structtag by parsing the tag
tags , err := structtag . Parse ( string ( tag ))
if err != nil {
panic ( err )
}
// iterate over al