本文整理匯總了Golang中net/url.URL.Values方法的典型用法代碼示例。如果您正苦於以下問題:Golang URL.Values方法的具體用法?Golang URL.Values怎麽用?Golang URL.Values使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net/url.URL
的用法示例。
在下文中一共展示了URL.Values方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Exec
// Exec executes the given request. Returns a GraphError if the response from Facebook is an error, or just
// a normal error if something goes wrong before that or during unmarshaling.
func (r *GraphRequest) Exec(target interface{}) error {
p := r.Path
if r.Version != Unversioned {
p = "/" + string(r.Version) + "/" + p
}
p = path.Clean(p)
url := url.URL{
Scheme: "https",
Host: "graph.facebook.com",
Path: p,
RawQuery: url.Values(r.Query).Encode(),
}
req, _ := http.NewRequest(string(r.Method), url.String(), nil)
if r.IsJSON {
req.Header.Add("Accept", "application/json")
}
resp, err := r.client.Do(req)
if err != nil {
return fmt.Errorf("error setting up http request: %s", err)
}
buf, err := ioutil.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("error reading response body")
}
if resp.StatusCode != 200 {
errorTarget := GraphError{}
err = json.Unmarshal(buf, &errorTarget)
if err != nil {
return fmt.Errorf("couldn't unmarshal response into Graph Error: %s\n\t%s", err, string(buf))
}
return errorTarget
}
if _, ok := target.(*[]byte); ok {
*(target.(*[]byte)) = buf
return nil
} else if r.IsJSON {
err = json.Unmarshal(buf, target)
if err != nil {
return fmt.Errorf("error unmarshaling response into %T: %s\n\n%s", target, err, string(buf))
}
} else {
return fmt.Errorf("invalid target type for non-json response: %T", target)
}
return nil
}