Skip to content

Instantly share code, notes, and snippets.

@hernan43
Created March 4, 2013 16:24
Show Gist options
  • Save hernan43/5083452 to your computer and use it in GitHub Desktop.
Save hernan43/5083452 to your computer and use it in GitHub Desktop.
Just playing around with Go
package main
import (
"fmt"
"encoding/json"
"io/ioutil"
"net/http"
)
func main() {
fmt.Printf("Trying GitHub call")
var oauth = "1588399ad0f28b2582903bcc9c767e3bfeb17977"
var url = fmt.Sprintf("https://api.github.com/repos/deltak/moodle/commits/151d40a4f02?access_token=%s", oauth)
var resp, _ = http.Get(url)
defer resp.Body.Close()
jsonBytes, _ := ioutil.ReadAll(resp.Body)
var data interface{}
err := json.Unmarshal(jsonBytes, &data)
m := data.(map[string]interface{})
if err != nil {
fmt.Printf("\nERROR: %s\n", err)
} else {
fmt.Printf("\nDATA:\n")
if _, exists := m["message"]; exists {
message := m["message"].(string)
fmt.Printf("Error fetching commit: %s\n", message)
} else {
commit := m["commit"].(map[string]interface{})
message := commit["message"].(string)
fmt.Printf("Message: %s\n", message)
fmt.Printf("COMMIT INFO: %s\n", commit)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment