This commit is contained in:
crusader 2018-08-23 18:28:10 +09:00
parent 9d80d778c6
commit ef45ff4ad6

View File

@ -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
} }