diff --git a/.github/workflows/include.yml b/.github/workflows/include.yml new file mode 100644 index 0000000..a0986ec --- /dev/null +++ b/.github/workflows/include.yml @@ -0,0 +1,31 @@ +# Same as full workflow (eg from fortio/gvi) but without the goreleaser step +name: "shared fortio workflows" + +on: + push: + branches: [ main ] # put back once testing with pre-releases on branch is done. + tags: + - 'v*' + pull_request: + branches: [ main ] + +jobs: + call-gochecks: + uses: fortio/workflows/.github/workflows/gochecks.yml@main +# call-codecov: +# uses: fortio/workflows/.github/workflows/codecov.yml@main +# secrets: +# CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + call-codeql: + uses: fortio/workflows/.github/workflows/codeql-analysis.yml@main + releaser-h2cli: + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') + uses: fortio/workflows/.github/workflows/releaser.yml@main + with: + description: "Simple http 2.0 (h2 and h2c) client in go, including streaming" + binary_name: "h2cli" + dockerfile: "./Dockerfile" + secrets: + GH_PAT: ${{ secrets.GH_PAT }} + DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} + DOCKER_USER: ${{ secrets.DOCKER_USER }} diff --git a/.gitignore b/.gitignore index 66fd13c..aaf1d79 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ # Dependency directories (remove the comment below to include it) # vendor/ +.golangci.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8ffe6f1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM scratch +COPY h2cli /usr/bin/h2cli +ENV HOME=/home/user +ENTRYPOINT ["/usr/bin/h2cli"] diff --git a/README.md b/README.md index 1d210f1..9f81983 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ Simple http 2.0 (h2) client in go including h2c (http2 over clear text, not requ go install github.com/fortio/h2cli@latest ``` +or see the binary releases. + ## Running Options/flags: diff --git a/h2cli.go b/h2cli.go index f224487..3a066d4 100644 --- a/h2cli.go +++ b/h2cli.go @@ -72,8 +72,9 @@ func main() { AllowHTTP: true, // to get h2c // Trick to get h2c without TLS: // thanks to https://github.com/thrawn01/h2c-golang-example/blob/master/README.md - DialTLS: func(network, addr string, cfg *tls.Config) (net.Conn, error) { - return net.Dial(network, addr) + DialTLSContext: func(ctx context.Context, network, addr string, _ *tls.Config) (net.Conn, error) { + var d net.Dialer + return d.DialContext(ctx, network, addr) }, } } @@ -87,12 +88,14 @@ func main() { if err != nil { log.Fatalf("Request method %q url %q error: %v", *method, *urlFlag, err) } + //nolint:gosec // yes we want to fetch the url given as input. resp, err := client.Do(req) if err != nil { log.Fatalf("Failed %q %q - error: %v", *method, *urlFlag, err) } if *stream { - n, err := io.Copy(os.Stdout, resp.Body) + var n int64 + n, err = io.Copy(os.Stdout, resp.Body) log.Infof("Response code %d, proto %s, size %d", resp.StatusCode, resp.Proto, n) if err != nil { log.Fatalf("Error copying response body: %v", err)