Solution 3

This commit is contained in:
holooooo
2021-05-16 14:18:34 +08:00
parent 84946743d9
commit 599e03b0cd
4 changed files with 123 additions and 256 deletions

View File

@@ -663,30 +663,12 @@ func (b *BeegoHTTPRequest) Response() (*http.Response, error) {
// ResponseForValue attempts to resolve the response body to value using an existing method.
// Calls Response inner.
// If value type is **string or **[]byte, the func directly passes response body into the pointer.
// Else if response header contain Content-Type, func will call ToJSON\ToXML\ToYAML.
// Finally it will try to parse body as json\yaml\xml, If all attempts fail, an error will be returned
// If response header contain Content-Type, func will call ToJSON\ToXML\ToYAML.
// Else it will try to parse body as json\yaml\xml, If all attempts fail, an error will be returned
func (b *BeegoHTTPRequest) ResponseForValue(value interface{}) error {
if value == nil {
return nil
}
// handle basic type
switch v := value.(type) {
case **string:
s, err := b.String()
if err != nil {
return nil
}
*v = &s
return nil
case **[]byte:
bs, err := b.Bytes()
if err != nil {
return nil
}
*v = &bs
return nil
}
resp, err := b.Response()
if err != nil {