Created
March 4, 2013 16:24
-
-
Save hernan43/5083452 to your computer and use it in GitHub Desktop.
Just playing around with Go
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" | |
"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