Skip to content

Commit

Permalink
Switch to using github.com/carlmjohnson/requests for getting file sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
rabadin committed Nov 28, 2024
1 parent dbdcd5f commit 0575bde
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ toolchain go1.23.0

require (
github.com/carlmjohnson/requests v0.24.2
github.com/dustin/go-humanize v1.0.1
github.com/pelletier/go-toml/v2 v2.2.3
github.com/rs/zerolog v1.33.0
github.com/spf13/cobra v1.8.1
Expand All @@ -14,7 +15,6 @@ require (

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand Down
19 changes: 15 additions & 4 deletions internal/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sync/atomic"
"time"

"github.com/carlmjohnson/requests"
"github.com/dustin/go-humanize"
"github.com/rs/zerolog/log"
)
Expand Down Expand Up @@ -98,14 +99,24 @@ func (st *StatusLine) InitResourcesSizes() error {
st.totalBytes = 0
for i, r := range *st.resources {
resource := r
httpClient := &http.Client{Timeout: time.Duration(timeoutMs) * time.Millisecond}
resp, err := httpClient.Head(resource.Urls[0])
headers := http.Header{}
err := requests.
URL(resource.Urls[0]).
Head().
CopyHeaders(headers).
CheckStatus(http.StatusOK).
Fetch(context.Background())
if err != nil {
log.Debug().Msg("Error fetching resource sizes")
return err
}
st.totalBytes += resp.ContentLength
st.resourceSizes[i] = resp.ContentLength
ContentLength, err := strconv.Atoi(headers.Get("Content-Length"))
if err != nil {
log.Debug().Msg("Error fetching resource sizes")
return err
}
st.totalBytes += int64(ContentLength)
st.resourceSizes[i] = int64(ContentLength)
}

return nil
Expand Down

0 comments on commit 0575bde

Please sign in to comment.