Skip to content

Commit

Permalink
Merge pull request #127 from fangyincheng/attachments
Browse files Browse the repository at this point in the history
Imp:  attachments
  • Loading branch information
AlexStocks committed Sep 2, 2019
2 parents feb0051 + 13e9374 commit 85a0add
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
19 changes: 17 additions & 2 deletions request.go
Expand Up @@ -321,7 +321,22 @@ func unpackRequestBody(buf []byte, reqObj interface{}) error {
if err != nil {
return perrors.WithStack(err)
}
req[6] = attachments
if v, ok := attachments.(map[interface{}]interface{}); ok {
req[6] = ToMapStringString(v)
return nil
}

return perrors.Errorf("get wrong attachments: %+v", attachments)
}

return nil
func ToMapStringString(origin map[interface{}]interface{}) map[string]string {
dest := make(map[string]string)
for k, v := range origin {
if kv, ok := k.(string); ok {
if vv, ok := v.(string); ok {
dest[kv] = vv
}
}
}
return dest
}
18 changes: 9 additions & 9 deletions response.go
Expand Up @@ -174,11 +174,11 @@ func unpackResponseBody(buf []byte, resp interface{}) error {
if err != nil {
return perrors.WithStack(err)
}
atta, ok := attachments.(map[string]string)
if ok {
if v, ok := attachments.(map[interface{}]interface{}); ok {
atta := ToMapStringString(v)
response.Attachments = atta
} else {
return perrors.Errorf("get wrong attachments: %+v", atta)
return perrors.Errorf("get wrong attachments: %+v", attachments)
}
}

Expand All @@ -199,11 +199,11 @@ func unpackResponseBody(buf []byte, resp interface{}) error {
if err != nil {
return perrors.WithStack(err)
}
atta, ok := attachments.(map[string]string)
if ok {
if v, ok := attachments.(map[interface{}]interface{}); ok {
atta := ToMapStringString(v)
response.Attachments = atta
} else {
return perrors.Errorf("get wrong attachments: %+v", atta)
return perrors.Errorf("get wrong attachments: %+v", attachments)
}
}

Expand All @@ -215,11 +215,11 @@ func unpackResponseBody(buf []byte, resp interface{}) error {
if err != nil {
return perrors.WithStack(err)
}
atta, ok := attachments.(map[string]string)
if ok {
if v, ok := attachments.(map[interface{}]interface{}); ok {
atta := ToMapStringString(v)
response.Attachments = atta
} else {
return perrors.Errorf("get wrong attachments: %+v", atta)
return perrors.Errorf("get wrong attachments: %+v", attachments)
}
}
return nil
Expand Down

0 comments on commit 85a0add

Please sign in to comment.