
Client Stream
Previous parts: Writing HTTP3 Server HTTP3 Client Server Stream Today we will create our own HTTP/3 client stream to send some sweet-sweet data to the server. Streaming data from the client can be used for sending large or real-time data uploads, such as file uploads, telemetry, or live feeds. With HTTP/3 and Go, you can efficiently stream request bodies without buffering the entire payload in memory. Streaming Client Request This is similar to streaming a request body in regular HTTP. We’ll use an io.Pipe to write data from the client as it becomes available, while the server reads the stream as it arrives. ...

Golden Tests
Use golden files for testing APIs

Webview
Create desktop applications using Go and Webview, packaging them into a single executable.

Server Stream
Previous parts: Writing HTTP3 Server HTTP3 Client Server-side streaming allows you to send data to the client as it becomes available, rather than waiting for the entire response to be ready. This is particularly useful for applications that require real-time updates, such as chat applications, live feeds, or large file transfers. Streaming Server Response This part is similar to the regular HTTP response streaming via http.ResponseWriter. We will stream data from the server as soon as it becomes available, without buffering. For this, we will use the http.Flusher interface, which allows us to flush the response buffer to the client immediately. For reference on how to implement a basic HTTP/3 server, check out Writing HTTP3 Server. ...
HTTP/3 Client
Previous parts: Writing HTTP3 Server Today, we will create an HTTP/3 client to interact with our HTTP/3 Server. First of all, you’ll need a running HTTP/3 server. Run it in a separate terminal: go run server.go Client skipping TLS verification Let’s write a simple HTTP/3 client for our server. It’s pretty straightforward: we need to create a new HTTP/3 transport and pass it to an HTTP client from net/http. Because HTTP/3 is built on top of QUIC, it requires us to use TLS. Since we are using a self-generated certificate in the server, the client can’t verify the certificate. One of the options is to skip TLS verification on the client: ...
Writing HTTP/3 Server
Today, we will go through the process of setting up a simple HTTP/3 server and verifying its functionality. We will be using quic-go for for this purpose. Generating Certificate Since HTTP/3 requires all traffic to be encrypted, we’ll need a certificate. For our test, we can generate a self-signed TLS certificate for localhost. Go has a build-in tool, which you can run like this: go run $(go env GOROOT)/src/crypto/tls/generate_cert.go --host localhost $(go env GOROOT) will evaluate to the GOROOT path for whatever version of Go you are using. ...

Test smell
This part is mostly about gut feelings. When you are writing tests or updating the code and something feels wrong, that is a sign that this is a test smell. Tests should be your helpers; you should work with them, not against them. Tests are your guide for safe refactoring. Tests should enable refactoring, not prevent it. If it seems you are changing internals but need to rewrite the tests, the tests are not testing the behavior, but rather the implementation. ...
Build a Docker image with private repos
To build a Docker image that has dependencies from private repositories, you should pass the .netrc configuration (see more in How to access private repos in Go). Ideally, this configuration should be passed as a secret: FROM golang:1.22.2-alpine3.19 AS deps COPY go.mod go.sum ./ # Copy secrets from /kaniko for Kaniko or from /run/secrets for Podman/Buddah RUN --mount=type=secret,id=netrc \ cp /kaniko/netrc "$HOME"/.netrc || cp /run/secrets/netrc "$HOME"/.netrc && \ go mod download && \ rm "$HOME"/.netrc GitLab CI/CD In GitLab CI, to build the image, you need to create a .netrc configuration with CI_JOB_TOKEN and pass it to Kaniko secrets. Here is an example: ...
How to access private repos in Go
When downloading packages, Go checks the public Go Checksum Database to verify the package checksum. Private Git packages, such as those on a private GitLab instance, aren’t in that database, so downloading them will fail. This can be fixed by setting GOPRIVATE=private.example.com. This instructs Go not to check the Checksum Database for packages in the private.example.com domain. For GitLab, first set up access to repositories: Create a GitLab Access Token with the read_api scope. Update your ${HOME}/.netrc file, and add: machine private.example.com login your.email@example.com password gitlab_access_token More information can be found in the GitLab documentation. ...
Set up a different Go version for a project
Let’s say you have Go 1.20.1 installed locally, but the project you are working on requires Go 1.22.3. First, install the additional version of the Go SDK. VS Code Set GOROOT to point to the Go version you need. Add the following to the workspace settings: "go.goroot": "${env:HOME}/sdk/go1.22.3" GoLand Go to Settings → Go → GOROOT and add or select the version you need there.