fix digitalocean v2 api content-type when using json
In case of using json we need to set content-type header. Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
parent
399837b048
commit
a5dc41a730
|
@ -24,7 +24,7 @@ type Size struct {
|
||||||
Memory uint `json:"memory,omitempty"` //only in v2 api
|
Memory uint `json:"memory,omitempty"` //only in v2 api
|
||||||
VCPUS uint `json:"vcpus,omitempty"` //only in v2 api
|
VCPUS uint `json:"vcpus,omitempty"` //only in v2 api
|
||||||
Disk uint `json:"disk,omitempty"` //only in v2 api
|
Disk uint `json:"disk,omitempty"` //only in v2 api
|
||||||
Transfer uint `json:"transfer,omitempty"` //only in v2 api
|
Transfer float64 `json:"transfer,omitempty"` //only in v2 api
|
||||||
PriceMonthly float64 `json:"price_monthly,omitempty"` //only in v2 api
|
PriceMonthly float64 `json:"price_monthly,omitempty"` //only in v2 api
|
||||||
PriceHourly float64 `json:"price_hourly,omitempty"` //only in v2 api
|
PriceHourly float64 `json:"price_hourly,omitempty"` //only in v2 api
|
||||||
Regions []string `json:"regions,omitempty"` //only in v2 api
|
Regions []string `json:"regions,omitempty"` //only in v2 api
|
||||||
|
|
|
@ -285,17 +285,21 @@ func NewRequestV2(d DigitalOceanClientV2, path string, method string, req interf
|
||||||
enc.Encode(req)
|
enc.Encode(req)
|
||||||
defer buf.Reset()
|
defer buf.Reset()
|
||||||
request, err = http.NewRequest(method, url, buf)
|
request, err = http.NewRequest(method, url, buf)
|
||||||
|
request.Header.Add("Content-Type", "application/json")
|
||||||
} else {
|
} else {
|
||||||
request, err = http.NewRequest(method, url, nil)
|
request, err = http.NewRequest(method, url, nil)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the authentication parameters
|
// Add the authentication parameters
|
||||||
request.Header.Add("Authorization", "Bearer "+d.APIToken)
|
request.Header.Add("Authorization", "Bearer "+d.APIToken)
|
||||||
|
if buf != nil {
|
||||||
|
log.Printf("sending new request to digitalocean: %s buffer: %s", url, buf)
|
||||||
|
} else {
|
||||||
log.Printf("sending new request to digitalocean: %s", url)
|
log.Printf("sending new request to digitalocean: %s", url)
|
||||||
|
}
|
||||||
resp, err := client.Do(request)
|
resp, err := client.Do(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -325,7 +329,10 @@ func NewRequestV2(d DigitalOceanClientV2, path string, method string, req interf
|
||||||
return errors.New(fmt.Sprintf("Failed to decode JSON response %s (HTTP %v) from DigitalOcean: %s", err.Error(),
|
return errors.New(fmt.Sprintf("Failed to decode JSON response %s (HTTP %v) from DigitalOcean: %s", err.Error(),
|
||||||
resp.StatusCode, body))
|
resp.StatusCode, body))
|
||||||
}
|
}
|
||||||
|
switch resp.StatusCode {
|
||||||
|
case 403, 429, 422, 404, 503, 500:
|
||||||
|
return errors.New(fmt.Sprintf("digitalocean request error: %+v", res))
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// see https://api.digitalocean.com/images/?client_id=[client_id]&api_key=[api_key]
|
// see https://api.digitalocean.com/images/?client_id=[client_id]&api_key=[api_key]
|
||||||
// name="Ubuntu 12.04.4 x64", id=3101045,
|
// name="Ubuntu 12.04.4 x64", id=6374128,
|
||||||
const DefaultImage = "ubuntu-12-04-x64"
|
const DefaultImage = "ubuntu-12-04-x64"
|
||||||
|
|
||||||
// see https://api.digitalocean.com/regions/?client_id=[client_id]&api_key=[api_key]
|
// see https://api.digitalocean.com/regions/?client_id=[client_id]&api_key=[api_key]
|
||||||
|
|
Loading…
Reference in New Issue