Tag golang

Be aware of copying in Go

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.

How to send multiple variables via channel in golang?

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.