本文整理匯總了Golang中github.com/drone/go-bitbucket/oauth1.Consumer.Sign方法的典型用法代碼示例。如果您正苦於以下問題:Golang Consumer.Sign方法的具體用法?Golang Consumer.Sign怎麽用?Golang Consumer.Sign使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/drone/go-bitbucket/oauth1.Consumer
的用法示例。
在下文中一共展示了Consumer.Sign方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: do
func (c *Client) do(method string, path string, params url.Values, values url.Values, v interface{}) error {
// if this is the guest client then we don't need
// to sign the request ... we will execute just
// a simple http request.
if c == Guest {
return c.guest(method, path, params, values, v)
}
// create the client
var client = oauth1.Consumer{
ConsumerKey: c.ConsumerKey,
ConsumerSecret: c.ConsumerSecret,
}
// create the URI
uri, err := url.Parse("https://api.bitbucket.org/1.0" + path)
if err != nil {
return err
}
if params != nil && len(params) > 0 {
uri.RawQuery = params.Encode()
}
// create the access token
token := oauth1.NewAccessToken(c.AccessToken, c.TokenSecret, nil)
// create the request
req := &http.Request{
URL: uri,
Method: method,
ProtoMajor: 1,
ProtoMinor: 1,
Close: true,
}
if values != nil && len(values) > 0 {
body := []byte(values.Encode())
buf := bytes.NewBuffer(body)
req.Body = ioutil.NopCloser(buf)
}
// add the Form data to the request
// (we'll need this in order to sign the request)
req.Form = values
// sign the request
if err := client.Sign(req, token); err != nil {
return err
}
// make the request using the default http client
resp, err := DefaultClient.Do(req)
if err != nil {
return err
}
// Read the bytes from the body (make sure we defer close the body)
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
// Check for an http error status (ie not 200 StatusOK)
switch resp.StatusCode {
case 404:
return ErrNotFound
case 403:
return ErrForbidden
case 401:
return ErrNotAuthorized
case 400:
return ErrBadRequest
}
// Unmarshall the JSON response
if v != nil {
return json.Unmarshal(body, v)
}
return nil
}