Skip to content

Commit

Permalink
fix lint alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
gamoutatsumi committed Jun 14, 2024
1 parent d5f58da commit 3e62001
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pkg/docker/ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/golang-jwt/jwt/v4"
)

type RateLimit struct {
type rateLimit struct {
Limit int
Remaining int
}
Expand Down Expand Up @@ -61,29 +61,30 @@ func getToken() (string, error) {
return tokenString, nil
}

func GetRateLimit() (RateLimit, error) {
// GetRateLimit get Docker Hub API rate limit
func GetRateLimit() (rateLimit, error) {

Check failure on line 65 in pkg/docker/ratelimit.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

exported func GetRateLimit returns unexported type docker.rateLimit, which can be annoying to use
token, err := getToken()
if err != nil {
return RateLimit{}, fmt.Errorf("get token: %w", err)
return rateLimit{}, fmt.Errorf("get token: %w", err)
}
url := "https://registry-1.docker.io/v2/ratelimitpreview/test/manifests/latest"
req, err := http.NewRequest("HEAD", url, nil)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
resp, err := http.DefaultClient.Do(req)
if err != nil {
return RateLimit{}, fmt.Errorf("get rate limit: %w", err)
return rateLimit{}, fmt.Errorf("get rate limit: %w", err)
}
defer resp.Body.Close()
limit, err := strconv.Atoi(strings.Split(resp.Header.Get("ratelimit-limit"), ";")[0])
if err != nil {
return RateLimit{}, fmt.Errorf("parse limit: %w", err)
return rateLimit{}, fmt.Errorf("parse limit: %w", err)
}
remaining, err := strconv.Atoi(strings.Split(resp.Header.Get("ratelimit-remaining"), ";")[0])
if err != nil {
return RateLimit{}, fmt.Errorf("parse remaining: %w", err)
return rateLimit{}, fmt.Errorf("parse remaining: %w", err)
}

return RateLimit{
return rateLimit{
Limit: limit,
Remaining: remaining,
}, nil
Expand Down

0 comments on commit 3e62001

Please sign in to comment.