The motivation behind this package is that the StructTag
implementation shipped with Go's standard library is very limited in
detecting a malformed StructTag and each time StructTag.Get(key)
gets called,
it results in the StructTag
being parsed again.
This package provides a way to parse the StructTag
into a structtag.Map
.
// Example of struct using tags to append metadata to fields.
type Server struct {
Host string `json:"host" env:"SERVER_HOST" default:"localhost"`
Port int `json:"port" env:"SERVER_PORT" default:"3000"`
}
go get github.com/quartercastle/structtag
tags, err := structtag.Parse(`json:"host" env:"SERVER_HOST"`)
if err != nil {
panic(err)
}
fmt.Println(tags["json"])
See godoc for full documentation.
This project is licensed under the MIT License.