Golden Tests

Use golden files for testing APIs

June 4, 2025 · 4 min

Webview

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

May 28, 2025 · 6 min

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: ...

January 19, 2025 · 2 min

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. ...

August 26, 2024 · 1 min

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.

August 26, 2024 · 1 min

Go Links

This page is a collection of useful links about Go. Getting started Tutorial: Get started with Go - Start here. Effective Go - Continue here. Documentation Documentation - Page with links to official documentation. Managing Go installation - Installing additional Go versions. Go Wiki Go Wiki: Home - It is a collection of information about Go and a curated list of articles about Go. Go Wiki: All Wiki Pages - All articles. Selected Code Review Comments - Common mistakes and best practices when writing code. Test Comments - Common mistakes and best practices when writing tests. The Go Blog Strings, bytes, runes and characters in Go - Difference between string, []byte, rune , UTF-8 and how to iterate over them. Blog Index - All articles. Style guides Uber Go Style Guide Google Go Style Guide Containers Multi-Stage builds - Multistage builds with Go. Organizing code Organizing a Go module - Official one. Go Project Layout - It is not an official one, but it can be used to gather ideas on where to put some exotic parts of the repo. Basic structures internals How Go Arrays Work Slices in Go Go Maps Explained Golang Defer Concurrency primitives Go sync.Mutex: Normal and Starvation Mode Go sync.WaitGroup and The Alignment Problem Go sync.Pool and the Mechanics Behind It Go sync.Cond, the Most Overlooked Sync Mechanism Go Singleflight Melts in Your Code, Not in Your DB Other How I write HTTP services in Go after 13 years - Good ideas around building production quality Go HTTP services. Go Concurrency Patterns: Pipelines and cancellation - How to write a concurrent pipeline. Pipeline with errgroup package Package rheos provides generalized approach for this pattern. Ultimate Visual Guide to Go Enums and iota - All about Enums and iota. Using ldflags to Set Version Information for Go Applications - Injecting stuff during build time. v2 and Beyond - how to release a new major version: Go Modules: v2 and Beyond A pragmatic guide to Go module updates Go Error Propagation and API Contracts - TLDR; Errors are the part of your public interface too. Graceful Shutdown in Go: Practical Patterns - Handling signals for graceful shutdowns.

August 26, 2024 · 2 min