Created
October 2, 2017 02:51
-
-
Save gnilchee/af65b1208e7249795b2187780dacae49 to your computer and use it in GitHub Desktop.
Some simple get examples using SendGrid's REST against Github API
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
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