Piotr Belina

Welcome to my blog.

  • I live in Gdańsk, Poland
  • I am a Software Engineer & DevOps Engineer
  • I am specialising in Go, Kubernetes and AWS

slog access log

Recently I wanted to learn more about Go’s slog package. Also for some other project I needed to create an access logger. I could not find a solution so I decided to create my own. I was inspired by two solutions: rs/zerolog/hlog package great guide at betterstack Working code example can be found on GitHub Requirements In my logger I wanted to have all standard data: request duration, status code, bytes written, method, url, user agent, remote addr plus some extra...

April 8, 2024 · 4 min

Trusted local certificates with mkcert and Go TLS server

When working on local environment, it is useful to use trusted TLS certificates. For this purpose we can use mkcert. mkcert automatically creates and installs a local CA in the system root store, and generates locally-trusted certificates. Working code example can be found on GitHub Instalation First we need to install it ❯ mkcert -install The local CA is already installed in the system trust store! 👍 The local CA is already installed in the Firefox trust store!...

April 5, 2024 · 2 min

GTD: remove „To File” drawer

I was rereading David Allen’s Getting Things Done recently. I needed to restart my GTD system and it was a good opportunity to review the original system proposed by David Allen. When I was reading Chapter 6 about second step Clarifying, I found a fragment that applies to me. (…) In my early days of coaching I used to give my clients permission to keep a To File pile. No longer....

March 31, 2024 · 1 min

Adding trace id to access log with rs/zerolog

This is an code based on opentelemetry dice example which uses rs/zerolog and adds trace id to logs. Working code example can be found on GitHub TraceIDHandler This is a standard access logger. What is extra here is traceID := traceIDHandler("trace_id", "span_id") traceIDHandler adds those two fields to zerolog if it finds them in context. func requestLogger(next http.Handler) http.Handler { h := hlog.NewHandler(logger) accessHandler := hlog.AccessHandler(func(r *http.Request, status, size int, duration time....

March 25, 2024 · 4 min

Go Graceful Shutdown

Graceful shutdown is a technique used to smoothly terminate an app. It allows the clients to receive data from the app. Also it gives time for the load balancer to deregister it and not send a traffic to it. // this is not an app with graceful shutdown package main import ( "fmt" "log" "net/http" "time" ) // this request takes long time to complete func indexHandler(w http.ResponseWriter, r *http.Request) { log....

November 27, 2023 · 4 min

Healthchecks - two most important Pod endpoints - Readiness & Liveness Check with Go examples

Every application should contain at least two endpoints: readiness check, health check. Readiness check should indicate when the app is ready to serve traffic. It should allow traffic when the app is correctly initialized. For example it should wait for the database connection to be established. The connection to cache or external API as well. This probe allows to cut off the traffic in case the app is unable to handle it....

November 12, 2023 · 3 min

Configuring Go application with flags, pflags, environment variables and Viper

There are multiple ways to configure your Go application. I will describe a few most common one in this article with code samples. Flags Go supports command line flags with builtin package flag. package main import ( "flag" "log" "net/http" ) func main() { addrPtr := flag.String("addr", ":8000", "addr of http server") flag.Parse() log.Printf("Listening on %s", *addrPtr) log.Fatal(http.ListenAndServe(*addrPtr, nil)) } func main() { var addr string flag.StringVar(&addr, "addr", ":8000", "addr of http server") flag....

November 6, 2023 · 3 min

Serving Static Website With Go

Serving static website in Go I would like to describe here how to serve static content with Go. Go http package provides handy function http.FileServer to serve such content. FileServer also allows to browse files when index.html is missing in a catalog. Preparing files Let’s create such structure. $ tree . ├── assets │ ├── page.html │ └── styles │ └── main.css └── main.go File: assets/page.html <!doctype html> <html> <head> <meta charset="utf-8"> <title>Document</title> <link rel="stylesheet" href="/styles/main....

October 25, 2023 · 2 min
Actual Budget - Open Source Alternative to YNAB

Actual Budget - Open Source Alternative to YNAB (with Kubernetes deployment)

When it comes to personal finance for long time I was using YNAB. The budgeting app based on zero based budget. I was YNAB user when it was a desktop app. I liked the fact that it was one-time purchase. But in 2015 the YNAB was rewritten in a SAAS application and switched to subscription model and currently it costs $99 annually. Me personally I think it is too much for such an app and I am not feeling comfortable with putting my financial data to online YNAB....

October 11, 2023 · 3 min

Taking Book Notes Video Summary

Recently I saw a video by Tiago Forte which seemed to me very interesting about taking book notes. It is an interview with Alex Wieckowski from Alex & Books in which he describes his method to get the most out of the book. TLDR Highlight the most interesting parts inside the book. Create your own table of contents at the first page of the book. Write down summary of the book in your own words at the last page of the book....

August 6, 2023 · 1 min