You should use the package github.com/pkg/errors instead of errors package for errors in your applications. The default package lacks a few things like: stack trace easy appending message to the error and more It helps with debugging a lot. Below you can find an example error message with the stack trace. An important thing to remember is that you should wrap every error which is from any external library or your freshly created error you want to return.
Golang uses a connection pool to manage opened connections for us. As a result, new connections are used when no free connection left and reuses them when golang finds an idle connection. The most important thing is that when two queries are called one by one it does not mean that the queries will use the same connection. It may be true if not in every case. In the example below, you can find two queries which may seem to be executed in one connection.
Some bugs are very hard to find and to reproduce but easy to fix. To avoid them, it’s helpful to know how the tools we’re using work under the hood. From this article, you’ll learn what shallow and deep copy are and which errors you can avoid thank’s the knowledge about them. Can you find a problem with the code below? q1 := NewQuestion(1, "How to be cool?") q1 = q1.
I’m glad that this year I read so many valuable books. I want to share with you with the most interesting items which you may find interesting too. Getting Things Programmed This book is only available in Polish. I would say that this is Getting Things Done but for developers. I think that the similarity of titles is not an accident. In this book, you can find answers on questions like:
Channels in golang are referenced type. It means that they are references to a place in the memory. The information can be used to achieve the goal. Firstly, let’s consider using structs as the information carrier. This is the most intuitive choice for the purpose. Below you can find an example of a struct which will be used today. type FuncResult struct { Err error Result int } func NewFuncResult(result int) FuncResult { return FuncResult{Result: result} } The idea is to create a channel from the struct, pass the channel to a function and wait for the result.
In 50′ and 60′ input data for programs from those years were written on paper tapes or punch cards. Writing code, compiling and testing loop took from a few hours to even few days. It was the beginning of programming we know it. At this time Dijkstra started his discovery. He conceived the algorithm called his name. He also noticed that programs become too complicated to be fully understood by one person.
Knowing the basics is the key to understanding more complex concepts. After reading this post you will know what are entities and value objects and find out differences between them. When you pay for something at a shop it’s not important which exactly coin you choose. The most important thing to the shop assistant is their value. It does not matter if you give him coin from the left or right pocket.
A few years ago, Scrum and Agile became very popular. It became mainstream. Everyone wanted to work on this framework. However, something’s changing. I remember when microservices were one of the most popular topics at many conferences. Everyone started talking about scalability and how cool they are. Because of that, many of those companies fell into the hell of microservices. Focusing on the tools that aren’t really appropriate for you at this time, can be even worse than not having it at all.
I’ve noticed that there is always a challenge of understanding what services are in a context of Domain-Driven Development and what is the difference between a service in an application, domain, and infrastructure layer. Domain-driven design made a lot of cleanup in the IT environment and conquered the hearts of programmers. Eric Evans is one of the most famous people who promote this not so a new way of developing software.
Recently, I took part in a hackathon. That was an excellent experience. Working 24 hours on a project you came up with the day before is very exciting. After that event, I realized something that I think I felt earlier – development is the easiest part of building a piece of software. It may sound weird but it’s true. In this article, I’ll tell you about my thoughts and conclusions that I have drawn.