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

resp.Json()默认不传参,用法更符合requests #24

Open
losenli opened this issue Jan 14, 2021 · 3 comments
Open

resp.Json()默认不传参,用法更符合requests #24

losenli opened this issue Jan 14, 2021 · 3 comments

Comments

@losenli
Copy link

losenli commented Jan 14, 2021

`func (resp *Response) Unmarshal(v interface{}) error {
if resp.content == nil {
resp.Content()
}
return json.Unmarshal(resp.content, v)
}

func (resp *Response) Json() (map[string]interface{}, error) {
var result = make(map[string]interface{})
if err := resp.Unmarshal(&result); err != nil {
return nil, err
}else {
return result, nil
}
}`

@asmcos
Copy link
Owner

asmcos commented Jan 14, 2021

我当时考虑,空间问题,和 增加了很多if,就没写成你说的那要。按照你说的,用起来更爽一些。

@losenli
Copy link
Author

losenli commented Jan 14, 2021

我当时考虑,空间问题,和 增加了很多if,就没写成你说的那要。按照你说的,用起来更爽一些。

加一个Unmarshal方法替换原来的Json(),新的Json()不需要传参,建议考虑下。嘻嘻。。

@asmcos
Copy link
Owner

asmcos commented Jan 15, 2021

嗯,你提交的代码我看了。很好,我考虑升级。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants