Skip to content

Commit

Permalink
and another fix for pointer options
Browse files Browse the repository at this point in the history
  • Loading branch information
bgentry committed Dec 20, 2013
1 parent 49acf3a commit 0b7a194
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions heroku.go
Expand Up @@ -21,7 +21,7 @@ import (
)

const (
Version = "0.4.2"
Version = "0.4.3"
DefaultAPIURL = "https://api.heroku.com"
DefaultUserAgent = "heroku-go/" + Version + " (" + runtime.GOOS + "; " + runtime.GOARCH + ")"
)
Expand Down Expand Up @@ -106,17 +106,23 @@ func (c *Client) NewRequest(method, path string, body interface{}) (*http.Reques
case io.Reader:
rbody = t
default:
if v := reflect.ValueOf(body); v.IsValid() {
t := v.Type()
if t.Kind() != reflect.Ptr || (reflect.Indirect(v).IsValid() && !reflect.Indirect(v).IsNil()) {
j, err := json.Marshal(body)
if err != nil {
log.Fatal(err)
}
rbody = bytes.NewReader(j)
ctype = "application/json"
v := reflect.ValueOf(body)
if !v.IsValid() {
break
}
if v.Type().Kind() == reflect.Ptr {
v = reflect.Indirect(v)
if !v.IsValid() {
break
}
}

j, err := json.Marshal(body)
if err != nil {
log.Fatal(err)
}
rbody = bytes.NewReader(j)
ctype = "application/json"
}
apiURL := strings.TrimRight(c.URL, "/")
if apiURL == "" {
Expand Down

0 comments on commit 0b7a194

Please sign in to comment.