Custom Tag Parsing
Read tags via reflection.
Reading Tags Yourself
You can define your own tag keys and read them at runtime with the reflect package. This lets you build custom behavior driven by metadata.
reflect.TypeOf
reflect.TypeOf returns a Type describing a value. From a struct Type you can inspect its fields.
package main
import (
"fmt"
"reflect"
)
type User struct {
Name string
}
func main() {
t := reflect.TypeOf(User{})
fmt.Println(t.Kind(), t.NumField())
}All lessons in this course
- What Are Struct Tags
- JSON Tags
- Validation Libraries
- Custom Tag Parsing