Created
December 1, 2017 16:08
-
-
Save kuzemkon/7b2689bd4a87ee46ce5864d43f15efc3 to your computer and use it in GitHub Desktop.
Creating HTTP request and handling response from it using Go lang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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