Skip to content

Instantly share code, notes, and snippets.

@kuzemkon
Created December 1, 2017 16:08
Show Gist options
  • Save kuzemkon/7b2689bd4a87ee46ce5864d43f15efc3 to your computer and use it in GitHub Desktop.
Save kuzemkon/7b2689bd4a87ee46ce5864d43f15efc3 to your computer and use it in GitHub Desktop.
Creating HTTP request and handling response from it using Go lang
data := new(StripeInitParams)
r.UnmarshalBody(data)
data.ClientSecret = util.Config.StripeTest
data.GrantType = "authorization_code"
requestJson, _ := json.Marshal(data)
req, _ := http.NewRequest("POST", "https://connect.stripe.com/oauth/token", bytes.NewBuffer(requestJson))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
response, _ := client.Do(req)
buf := new(bytes.Buffer)
buf.ReadFrom(response.Body)
if response.StatusCode != 200 {
return &api.ErrorResponse{Status: 400, Message: "Invalid Stripe client token"}
}
body := new(StripeResponseParams)
json.Unmarshal([]byte(buf.String()), &body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment