本文整理汇总了Golang中gnd/la/net/httpclient.Response类的典型用法代码示例。如果您正苦于以下问题:Golang Response类的具体用法?Golang Response怎么用?Golang Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Response类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: decodeListing
func decodeListing(resp *httpclient.Response) (*Listing, error) {
var value map[string]interface{}
err := resp.DecodeJSON(&value)
if err != nil {
return nil, err
}
data, ok := value["data"].(map[string]interface{})
if !ok {
return nil, ErrInvalidDataFormat
}
children, ok := data["children"].([]interface{})
if !ok {
return nil, ErrInvalidDataFormat
}
var stories []*Story
for _, v := range children {
story, err := decodeStory(v)
if err != nil {
return nil, err
}
stories = append(stories, story)
}
return &Listing{
Stories: stories,
}, nil
}
示例2: decodeResponseError
func decodeResponseError(resp *httpclient.Response) error {
c := &ErrorContainer{}
if err := resp.DecodeJSON(&c); err != nil {
return err
}
return fmt.Errorf("error from Facebook (type %v): %v", c.Error.Type, c.Error.Message)
}
示例3: googleError
func googleError(r *httpclient.Response) error {
data, _ := r.ReadAll()
var e *Error
if err := json.Unmarshal(data, &e); err == nil && e != nil && e.Message != "" {
return e
}
return fmt.Errorf("invalid status code %d: %s", r.StatusCode, string(data))
}
示例4: decodeError
func (c *Client) decodeError(r *httpclient.Response) error {
if c.DecodeError != nil {
return c.DecodeError(r)
}
data, err := r.ReadAll()
if err != nil {
return fmt.Errorf("error reading response: %s", err)
}
return errors.New(string(data))
}
示例5: parseJson
func parseJson(resp *httpclient.Response) (map[string]interface{}, error) {
var m map[string]interface{}
if err := resp.DecodeJSON(&m); err != nil {
return nil, err
}
if rresp, ok := m["resource_response"].(map[string]interface{}); ok {
if err, ok := rresp["error"].(map[string]interface{}); ok {
msg, _ := err["message"].(string)
if msg == "" {
msg, _ = err["code"].(string)
}
return nil, errors.New(msg)
}
}
return m, nil
}
示例6: decodeArgs
func decodeArgs(resp *httpclient.Response) (map[string]string, error) {
var m map[string]interface{}
if err := resp.DecodeJSON(&m); err != nil {
return nil, err
}
var args map[string]interface{}
if strings.HasSuffix(resp.Request.URL.Path, "post") {
args = m["form"].(map[string]interface{})
} else {
args = m["args"].(map[string]interface{})
}
values := make(map[string]string, len(args))
for k, v := range args {
values[k] = v.(string)
}
return values, nil
}
示例7: parseTwitterResponse
func parseTwitterResponse(resp *httpclient.Response, out interface{}) error {
if !resp.IsOK() {
var message string
var code int
var errs twitterErrors
if resp.DecodeJSON(&errs) == nil && len(errs.Errors) > 0 {
message = errs.Errors[0].Message
code = errs.Errors[0].Code
}
return &TwitterError{
Message: message,
Code: code,
StatusCode: resp.StatusCode,
}
}
if err := resp.DecodeJSON(out); err != nil {
return err
}
return nil
}
示例8: parseToken
func parseToken(resp *httpclient.Response) (*Token, error) {
defer resp.Close()
b, err := resp.ReadAll()
if err != nil {
return nil, err
}
s := string(b)
if !resp.IsOK() {
return nil, fmt.Errorf("oAuth service returned non-200 status code %d: %s", resp.StatusCode, s)
}
values, err := url.ParseQuery(s)
if err != nil {
return nil, err
}
key := values.Get("oauth_token")
secret := values.Get("oauth_token_secret")
if key == "" || secret == "" {
return nil, fmt.Errorf("can't parse token from %q", s)
}
return &Token{
Key: key,
Secret: secret,
}, nil
}
示例9: responseHasError
func (c *Client) responseHasError(r *httpclient.Response) bool {
if c.ResponseHasError != nil {
return c.ResponseHasError(r)
}
return !r.IsOK()
}
示例10: decodeError
func decodeError(r *httpclient.Response) error {
var m map[string]interface{}
r.UnmarshalJSON(&m)
message, _ := m["message"].(string)
return errors.New(message)
}