From b5528191dd052f3eafbf8a247ddcb94d4905d404 Mon Sep 17 00:00:00 2001 From: Michael Dales Date: Wed, 15 Oct 2025 13:24:05 +0100 Subject: [PATCH 1/3] Use custom http transport settings --- internal/utils/utils.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/internal/utils/utils.go b/internal/utils/utils.go index fec8dbc..3d2471b 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -5,15 +5,33 @@ import ( "errors" "fmt" "io" + "net" "net/http" "os" "path" "strings" "syscall" + "time" ) func HTTPGet(url string, headers map[string]string) (*http.Response, error) { - client := &http.Client{} + transport := &http.Transport{ + Dial: (&net.Dialer{ + Timeout: 30 * time.Second, + KeepAlive: 30 * time.Second, + }).Dial, + TLSHandshakeTimeout: 10 * time.Second, + ResponseHeaderTimeout: 10 * time.Second, + ExpectContinueTimeout: 1 * time.Second, + MaxIdleConns: 100, + MaxIdleConnsPerHost: 10, + DisableCompression: true, + } + + client := &http.Client{ + Transport: transport, + Timeout: 0, + } req, err := http.NewRequest("GET", url, nil) if nil != err { From 32fab2d5dbf5c7db457165e0afc3ff66a2c2e1de Mon Sep 17 00:00:00 2001 From: Michael Dales Date: Wed, 15 Oct 2025 13:42:52 +0100 Subject: [PATCH 2/3] Add download progress indicator --- go.mod | 12 +++++++++++- go.sum | 10 ++++++++++ internal/utils/utils.go | 8 +++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 7124683..1f06921 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,18 @@ module github.com/quantifyearth/reclaimer -go 1.22.2 +go 1.24.0 + +toolchain go1.24.4 require ( github.com/cheynewallace/tabby v1.1.1 github.com/golang-jwt/jwt v3.2.2+incompatible ) + +require ( + github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect + github.com/rivo/uniseg v0.4.7 // indirect + github.com/schollz/progressbar/v3 v3.18.0 // indirect + golang.org/x/sys v0.37.0 // indirect + golang.org/x/term v0.36.0 // indirect +) diff --git a/go.sum b/go.sum index 07f596f..d58514f 100644 --- a/go.sum +++ b/go.sum @@ -2,3 +2,13 @@ github.com/cheynewallace/tabby v1.1.1 h1:JvUR8waht4Y0S3JF17G6Vhyt+FRhnqVCkk8l4Yr github.com/cheynewallace/tabby v1.1.1/go.mod h1:Pba/6cUL8uYqvOc9RkyvFbHGrQ9wShyrn6/S/1OYVys= github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= +github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= +github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= +github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= +github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/schollz/progressbar/v3 v3.18.0 h1:uXdoHABRFmNIjUfte/Ex7WtuyVslrw2wVPQmCN62HpA= +github.com/schollz/progressbar/v3 v3.18.0/go.mod h1:IsO3lpbaGuzh8zIMzgY3+J8l4C8GjO0Y9S69eFvNsec= +golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= +golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q= +golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss= diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 3d2471b..2184962 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -12,6 +12,8 @@ import ( "strings" "syscall" "time" + + "github.com/schollz/progressbar/v3" ) func HTTPGet(url string, headers map[string]string) (*http.Response, error) { @@ -161,7 +163,11 @@ func DownloadFile(downloadURL string, targetFilename string, extract bool, desti return fmt.Errorf("unexpected HTTP status %d: %s", resp.StatusCode, resp.Status) } - _, err = io.Copy(out, resp.Body) + bar := progressbar.DefaultBytes( + resp.ContentLength, + "downloading", + ) + _, err = io.Copy(io.MultiWriter(out, bar), resp.Body) out.Close() if nil != err { return fmt.Errorf("failed to download file: %w", err) From e29fac96e8b061b04f828c442324ad9697d9ea8c Mon Sep 17 00:00:00 2001 From: Michael Dales Date: Wed, 15 Oct 2025 13:47:20 +0100 Subject: [PATCH 3/3] Add CI tests --- .github/workflows/ci.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..cc33c5b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,28 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21' + + - name: Download dependencies + run: go mod download + + - name: Build + run: go build -v ./... + + - name: Vet + run: go vet ./... \ No newline at end of file