Writing linters is simple. I was surprised how it’s easy to write a Go linter. Today, we’ll write a linter that will calculate the cyclomatic complexity of the Go code.

What is cyclomatic complexity?

Cyclomatic complexity is a software metric used to indicate the complexity of a program. ref

The idea is simple — every time we find any control flow statements we increase the complexity by one. I know I oversimplified it a bit but I don’t want to overwhelm you with unnecessary details.

There are a few steps we should follow to write our custom linter. Firstly, we…

In the last article, we wrote a few tests for a project to make sure that our refactoring won’t break anything. To understand the project better, we will separate the part of the domain and add a test to it. This will make the test more authentic.

There is a problem with the end-to-end (e2e) tests: database under the hood. This attitude is not carefree. Firstly, those tests are rather slow. It might be an issue when the number of tests will increase. We use a real database connection that has an overhead.

Secondly, those tests are not as stable…

When we talk about software design we very often use very generic and abstract words. But, how about the practice? How does it look in a real-world project? Today, you and I will start refactoring a small to-do app for better testability and maintainability. In this article, we will make the application testable. We’ll write black-box tests that will prevent some bugs and make future refactoring easier and safer.

This article is the first part of the mini-series where we do a code review of existing code and try to improve it. In future articles, we’ll extract the domain from…

In this article, I explain how you can detect if the interface you’re using is getting too big and requires splitting into smaller ones. Smaller interfaces help to improve the maintenance and readability of the code. What’s more, it helps with understanding the code.

Interfaces in Go are different than those known in Java, c#, PHP etc. In those languages you define interfaces up-front. In other words, at the moment of creating a class you need to know how the class will be used. In Go things are different. You can create a struct with as many functions you want…

The context package in Go is quite simple and well-known. On the other hand, there are some misunderstandings while using it. Today, I'll try to explain all the most popular concerns and make more clear when and how use the Context.

Let’s start with what the context is.

Package context defines the Context type, which carries deadlines, cancellation signals, and other request-scoped values across API boundaries and between processes. ref: https://golang.org/pkg/context/

In other words, the context is for stoping goroutines and it carries request-scoped values. What exactly does it mean in practice?

The most popular use case is when you…

I always had problems with negotiations. To be precise — it’s still a problem for me but I think that “ Never split a difference “ by Chris Voss will help me with this. Here are some things I took down I remember from the book the most.

The first thing is the mood. When we feel safe and in control, we are more problem-solvers. A smile makes as more open and ready for negotiation instead of fight and resist. That sounds reasonable but the next thing surpassed me.

Let them (your counterparts) say ‘no’ as soon as possible. The…

Making changes to all HTTP requests can be handy. You may want to add an API key or some information about the sender like app version etc. No matter why you want to do that you have a few options to achieve the goal.

The first approach is building a factory method that will add the required header.

func newRequest(endpoint string) *http.Request {
req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("https://%s", endpoint), nil)
req.Header.Add("x-api-key", "my-secret-token")
return req

It’s very simple and clear but it requires you to create a new method per HTTP method or calling another function directly. …

From time to time, I receive an email from a scammer that says he has X million dollars/euro for me. At the very beginning, I removed those emails but at some point, I decided to answer them. Here’s what I found. Every scammer starts very typically. There’s a very reach person who’s dying or very sick. They found my email on the Internet and learned that I’ll be the person who will spend the money wisely.

The first e-mail is very long and written using very good but clear English. Their English skills are better than mine! They explain everything…

Go has plenty of different web frameworks. When you are faced with choosing a framework for the first time, it may turn out to be quite a challenge to choose the best one. This article is intended to help you choose the best one. It is full of personal judgments that you may disagree with. However, I believe you will find it most helpful.


The first framework is Martini. Honestly, it shouldn’t be here as it’s been under development since 2017. However, I added it because I found it on other compilations. Just don’t use it :)


Gin is probably…

When I started my career as a software developer and published the first production application what I did was staring at logs and look for some fatal errors. It was a monolith application. Every log saying that something’s wrong had to be fixed. ASAP. This approach worked for some time. However, when the scale increased, and I started building microservices, I couldn’t get rid of all of them. Network issues, database failures, and more — it happens all the time.

No matter what — your application will experience outages. You have to accept it. What you should do is to…

Bartłomiej Klimczak

I'M a backend engineer at G2A, blogger, speaker and open-source developer :)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store