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 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 fec8dbc..2184962 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -5,15 +5,35 @@ import ( "errors" "fmt" "io" + "net" "net/http" "os" "path" "strings" "syscall" + "time" + + "github.com/schollz/progressbar/v3" ) 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 { @@ -143,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)