-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
53 lines (41 loc) · 976 Bytes
/
Copy pathmain.go
File metadata and controls
53 lines (41 loc) · 976 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
44
45
46
47
48
49
50
51
52
53
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"os"
"github.com/HackerManPeter/github-activity/config"
"github.com/HackerManPeter/github-activity/internal"
)
var conf = config.New()
func main() {
ctx := context.Background()
// get user input from cmd
args, err := internal.ReceiveArguments()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// fetch data from github
req := internal.BuildRequest(ctx, conf, args)
resp, err := internal.Client.Do(req)
if err != nil {
log.Fatal(err)
os.Exit(1)
}
if resp.StatusCode != 200 {
log.Fatalf("Unable to reach github ~ Status Code: %v", resp.StatusCode)
}
// decode data
var githubResponse []internal.GithubResponse
err = json.NewDecoder(resp.Body).Decode(&githubResponse)
if err != nil {
fmt.Printf("%v", err)
os.Exit(1)
}
// parse data
response := internal.ParseGithubResponse(githubResponse)
result := internal.FormatOutput(args.Username, response)
fmt.Print(result)
}