-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.go
More file actions
43 lines (33 loc) · 800 Bytes
/
github.go
File metadata and controls
43 lines (33 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"context"
"encoding/json"
"github.com/google/go-github/github" // with go modules disabled
"log"
)
type Gists struct {
Gist []string `json:"gist"`
Counter int
}
func GetGist(githubUser string) (Gists, error) {
if githubUser == "" {
return Gists{}, nil
}
client := github.NewClient(nil)
// list all public gists for githubUser
var list []string
gists, _, err := client.Gists.List(context.Background(), githubUser, nil)
if err != nil {
log.Println(err)
}
for _, g := range gists {
for _, v := range g.Files {
list = append(list, *v.RawURL)
}
}
gistCount := len(list)
G := Gists{list, gistCount}
jsonList, err := json.MarshalIndent(list, "", " ")
log.Printf("public gists for %s: %s\n", githubUser, string(jsonList))
return G, nil
}