Passed
Push — main ( a0a36f...588928 )
by Clive
03:45
created

main.main   A

Complexity

Conditions 3

Size

Total Lines 26
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 19
nop 0
dl 0
loc 26
rs 9.45
c 0
b 0
f 0
1
package main
2
3
import (
4
	"fmt"
5
	"go-github-token-limit/internal/utils"
6
	"net/http"
7
	"os"
8
	"time"
9
10
	"go-github-token-limit/internal/githubapi"
11
)
12
13
func main() {
14
	utils.InfoNotice(`                   GitHub Token Limit Checker                   `)
15
	utils.InfoNotice(`                             v1.0.0                             `)
16
	println("") // This is a placeholder for the main function
17
18
	client := &http.Client{}
19
	token := os.Getenv(githubapi.TokenEnvName)
20
21
	rateLimitResponse, err := githubapi.FetchRateLimit(client, token)
22
	if err != nil {
23
		utils.ErrorNotice(fmt.Sprintf("Error fetching rate limit: %v\n", err))
24
		os.Exit(3)
25
	}
26
27
	core := rateLimitResponse.Resources.Core
28
	resetTime := core.Reset.Time
29
	//fmt.Printf("%+v\n", core)
30
31
	if core.Remaining > 0 {
32
		utils.InfoNotice(fmt.Sprintf("     You have %d/%d requests left this hour", core.Remaining, core.Limit))
33
	} else {
34
		now := time.Now()
35
		durationUntilReset := resetTime.Sub(now).Minutes()
36
		utils.InfoNotice(fmt.Sprintf("     You have no requests left. The limit will reset in %.0f minute at %s", durationUntilReset, resetTime))
37
	}
38
	println("")
39
}
40