ing
This commit is contained in:
parent
9d80d778c6
commit
ef45ff4ad6
38
registry.go
38
registry.go
|
@ -129,21 +129,7 @@ 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])
|
||||||
|
|
||||||
if !AnnotationBodyRGX.MatchString(body) {
|
|
||||||
return nil, fmt.Errorf("Body[%s] of annotation[%s] is not valid", body, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
body = AnnotationBodyRGX.ReplaceAllStringFunc(body, func(token string) string {
|
|
||||||
switch len(token) {
|
|
||||||
case 0, 1, 2:
|
|
||||||
return "\"\""
|
|
||||||
default:
|
|
||||||
return strings.Replace(fmt.Sprintf("\"%s\"", token[1:len(token)-1]), "\\'", "'", -1)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
body = fmt.Sprintf("{%s}", strings.TrimSpace(body))
|
|
||||||
|
|
||||||
def, ok := r.definitions[name]
|
def, ok := r.definitions[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -153,9 +139,25 @@ func (r *AnnotationRegistry) getAnnotation(f *reflect.StructField) (map[reflect.
|
||||||
v := reflect.New(def.rt)
|
v := reflect.New(def.rt)
|
||||||
i := v.Interface()
|
i := v.Interface()
|
||||||
|
|
||||||
err := json.Unmarshal([]byte(body), i)
|
if "" != body {
|
||||||
if nil != err {
|
if !AnnotationBodyRGX.MatchString(body) {
|
||||||
return nil, fmt.Errorf("Unmarshal failed %v", err)
|
return nil, fmt.Errorf("Body[%s] of annotation[%s] is not valid", body, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
body = AnnotationBodyRGX.ReplaceAllStringFunc(body, func(token string) string {
|
||||||
|
switch len(token) {
|
||||||
|
case 0, 1, 2:
|
||||||
|
return "\"\""
|
||||||
|
default:
|
||||||
|
return strings.Replace(fmt.Sprintf("\"%s\"", token[1:len(token)-1]), "\\'", "'", -1)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
body = fmt.Sprintf("{%s}", strings.TrimSpace(body))
|
||||||
|
|
||||||
|
err := json.Unmarshal([]byte(body), i)
|
||||||
|
if nil != 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