Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imp: convert attachments to map[string]string #127

Merged
merged 3 commits into from Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion request.go
Expand Up @@ -321,7 +321,23 @@ 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)
} else {
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
wongoo marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
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 {
wongoo marked this conversation as resolved.
Show resolved Hide resolved
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