Add processing when pagination is nil

This commit is contained in:
178inaba 2017-05-06 23:34:42 +09:00
parent 134128cb56
commit 22f47735b4
2 changed files with 26 additions and 15 deletions

View file

@ -103,19 +103,18 @@ func (c *Client) doAPI(ctx context.Context, method string, uri string, params in
}
defer resp.Body.Close()
lh := resp.Header.Get("Link")
if lh != "" {
retPG, err := newPagination(lh)
if err != nil {
return err
}
*pg = *retPG
}
if resp.StatusCode != http.StatusOK {
return parseAPIError("bad request", resp)
} else if res == nil {
return nil
} else if pg != nil {
if lh := resp.Header.Get("Link"); lh != "" {
pg2, err := newPagination(lh)
if err != nil {
return err
}
*pg = *pg2
}
}
return json.NewDecoder(resp.Body).Decode(&res)
}