Skip to content

Instantly share code, notes, and snippets.

@gnilchee
Created October 2, 2017 02:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnilchee/af65b1208e7249795b2187780dacae49 to your computer and use it in GitHub Desktop.
Save gnilchee/af65b1208e7249795b2187780dacae49 to your computer and use it in GitHub Desktop.
Some simple get examples using SendGrid's REST against Github API
package main
import (
"fmt"
"encoding/json"
"github.com/sendgrid/rest"
)
func main() {
// var
url := "https://api.github.com/"
method := rest.Get
// make request and catch err
request := rest.Request{
Method: method,
BaseURL: url,
}
resp, err := rest.API(request)
if err != nil {
fmt.Println(err)
}
// Unmarshal body into body_map
body := []byte(resp.Body)
var body_iface interface{}
err = json.Unmarshal(body, &body_iface)
if err != nil {
fmt.Println(err)
}
body_map := body_iface.(map[string]interface{})
// lets select format with some output
fmt.Printf("Response: %v\n", resp.StatusCode)
fmt.Println()
fmt.Printf("Body: %v\n", body_map["current_user_url"].(string))
fmt.Println()
fmt.Printf("Headers: %v\n", resp.Headers["Status"])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment