Skip to content

Instantly share code, notes, and snippets.

@syguer
Created August 1, 2017 08:25
Show Gist options
  • Save syguer/f47a97cbfb3ef15045bc1e8376dc134b to your computer and use it in GitHub Desktop.
Save syguer/f47a97cbfb3ef15045bc1e8376dc134b to your computer and use it in GitHub Desktop.
package main
import (
"context"
"encoding/json"
"fmt"
"golang.org/x/oauth2"
"io/ioutil"
)
type GithubResponseLinks struct {
Git string `json:"git"`
Self string `json:"self"`
Html string `json:"html"`
}
type GithubResponse struct {
Type string `json:"type"`
Encoding string `json:"encoding"`
Size int `json:"size"`
Name string `json:"name"`
Path string `json:"path"`
Content string `json:"content"`
Sha string `json:"sha"`
Url string `json:"url"`
GitUrl string `json:"git_url"`
HtmlUrl string `json:"html_url"`
DownloadUrl string `json:"download_url"`
Links GithubResponseLinks `json:"_links"`
}
func main() {
ctx := context.Background()
tok := &oauth2.Token{
AccessToken: "xxxxx",
TokenType: "Bearer",
}
conf := &oauth2.Config{
ClientID: "xxxxxxxxxx",
ClientSecret: "xxxxxxxxxxxxxxxxx",
Scopes: []string{"repo"},
Endpoint: oauth2.Endpoint{
AuthURL: "http://github.com/login/oauth/authorize",
TokenURL: "https://github.com/login/oauth/access_token",
},
}
client := conf.Client(ctx, tok)
resp, err := client.Get("https://api.github.com/repos/syguer/xxxxxxxxx/contents/README.md")
if err != nil {
panic(err)
}
res := GithubResponse{}
body, _ := ioutil.ReadAll(resp.Body)
json.Unmarshal(body, &res)
fmt.Printf("%+v\n", res)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment