ing
This commit is contained in:
parent
9d80d778c6
commit
ef45ff4ad6
20
registry.go
20
registry.go
|
@ -129,8 +129,17 @@ func (r *AnnotationRegistry) getAnnotation(f *reflect.StructField) (map[reflect.
|
||||||
}
|
}
|
||||||
|
|
||||||
name := fmt.Sprintf("@%s", strings.TrimSpace(rs[1]))
|
name := fmt.Sprintf("@%s", strings.TrimSpace(rs[1]))
|
||||||
body := rs[2]
|
body := strings.TrimSpace(rs[2])
|
||||||
|
|
||||||
|
def, ok := r.definitions[name]
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("annotation[%s] is not exist", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
v := reflect.New(def.rt)
|
||||||
|
i := v.Interface()
|
||||||
|
|
||||||
|
if "" != body {
|
||||||
if !AnnotationBodyRGX.MatchString(body) {
|
if !AnnotationBodyRGX.MatchString(body) {
|
||||||
return nil, fmt.Errorf("Body[%s] of annotation[%s] is not valid", body, name)
|
return nil, fmt.Errorf("Body[%s] of annotation[%s] is not valid", body, name)
|
||||||
}
|
}
|
||||||
|
@ -145,18 +154,11 @@ func (r *AnnotationRegistry) getAnnotation(f *reflect.StructField) (map[reflect.
|
||||||
})
|
})
|
||||||
body = fmt.Sprintf("{%s}", strings.TrimSpace(body))
|
body = fmt.Sprintf("{%s}", strings.TrimSpace(body))
|
||||||
|
|
||||||
def, ok := r.definitions[name]
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("annotation[%s] is not exist", name)
|
|
||||||
}
|
|
||||||
|
|
||||||
v := reflect.New(def.rt)
|
|
||||||
i := v.Interface()
|
|
||||||
|
|
||||||
err := json.Unmarshal([]byte(body), i)
|
err := json.Unmarshal([]byte(body), i)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return nil, fmt.Errorf("Unmarshal failed %v", err)
|
return nil, fmt.Errorf("Unmarshal failed %v", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
annotations[def.t] = i
|
annotations[def.t] = i
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user