Handle the tags in pattern {key}:"{value}={arg1} {arg2} ... {argN}"
.
e.g.
package tagrunner
type hello struct {
World string `json:"field_hello" doctor:"hello=v1 v2"`
}
func main() {
target := &hello{World: "hi"}
runner := NewRunner()
runner.MustRegister("doctor", "hello", func(ctx context.Context, info *RunnerInfo) error {
// 对字段的处理逻辑
return nil
})
}
Contains all things needed to handle the field.
type RunnerInfo struct {
Key string
Value string
Args []string
Field *TagField
passBy interface{}
}
type TagField struct {
FieldValue reflect.Value
StructField reflect.StructField
Parent *TagField
}
Btw, you can use SetPassBy()
to pass something within a tag key.
Got error of type *RunnerError
, can use Unwrap()
to get the error thrown by handler.