golang auto generate struct tag
run this main.go
package main
import (
"fmt"
tag "gotag"
)
type User struct {
// @Tag: json bson
UserName string
Age int
}
type Book struct {
Name string
Author string
}
func main() {
tag.UseFilter(tag.FilterStruct)
tag.ParseFile("src/gotag/example2/main.go")
// you can also parae package
//tag.ParsePkg("src/gotag/example2/")
}
then you can see the user struct
type User struct {
// @Tag: json bson
UserName string `json:"user_name" bson:"user_name"`
Age int `json:"age" bson:"age"`
}
- you need write
@Tag:
comment on the first field of the struct - after the
@Tag:
, write you need the tag - see the struct user in example
- add or overloaded tag's translate handle: see this
- add or overloaded node's parse handle: see this
- use middleware to filter and parse node
If you do have a contribution for the package feel free to put up a Pull Request or open Issue.