Category Archives: golang

Integration tests with testcontainers-go

Here is the go library that simplifies integration tests with docker containers — https://github.com/testcontainers/testcontainers-go. That’s how you can use it to test sql — https://github.com/testcontainers/testcontainers-go/blob/master/docs/examples/cockroachdb.md. Project documentation — https://golang.testcontainers.org/features/docker_compose/ The idea is to prepare the environment, build your app, then make requests and check the DB state.

«Awesome go» resources

A list of good resources for each go specific part — https://github.com/avelino/awesome-go. A list of good tools for go performance or just fast libs — https://github.com/cristaloleg/awesome-go-perf Security lists — https://github.com/guardrailsio/awesome-golang-security, https://github.com/Binject/awesome-go-security

Go library for creating slack bots

You can use it like that: package main import ( «context» «github.com/shomali11/slacker» «log» ) func main() { bot := slacker.NewClient(«») definition := &slacker.CommandDefinition{ Handler: func(request slacker.Request, response slacker.ResponseWriter) { response.Reply(«pong») }, } bot.Command(«ping», definition) ctx, cancel := context.WithCancel(context.Background()) defer cancel() err := bot.Listen(ctx) if err != nil { log.Fatal(err) } } https://github.com/shomali11/slacker

How to work with core dumps of Go programs

If you want to check what is going on in your service during load (on production or during stress testing process), you can take a core dump of your app and load it into Goland for further debugging. # first you need to get your app’s PID ps aux|grep gcore # download dump file and …

Read more

Nice introductory article on why Golang is not OOP

It is a copy of this article — https://rakyll.org/typesystem/ It is real struggle to work with a new language, especially if the type doesn’t resemble what you have previously seen. I have been there with Go and lost my interest in the language when it first came out due to the reason I was pretending …

Read more

A way to test http client in go

A couple of ways are described here — http://hassansin.github.io/Unit-Testing-http-client-in-Go The way I liked is the following one: func Test_Mine(t *testing.T) { … client := httpClientWithRoundTripper(http.StatusOK, «OK») … } type roundTripFunc func(req *http.Request) *http.Response func (f roundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) { return f(req), nil } func httpClientWithRoundTripper(statusCode int, response string) *http.Client { return &http.Client{ Transport: …

Read more

Go internals

Channels https://youtu.be/KBZlN0izeiY Go scheduler https://youtu.be/YHRO5WQGh0k

Setup local Athens for proper go mod

There is a project called Athens for proxying all your go mod downloads. How to use it locally. 1. Create the following files and directories: a. /Users/d.bolgov/.ssh-athens/storage — empty directory to cache go modules b. /Users/d.bolgov/.ssh-athens/.netrc — if you prefer using .netrc machine github.com login [yourlogin] password [yourpassword] c. /Users/d.bolgov/.ssh-athens/gitconfig/.gitconfig — if you want to …

Read more

Installing protobuf tools on MacOS

Installing protoc brew install protobuf Or follow different instructions. Installing grpc_cli Option 1. Easy way. brew tap grpc/grpc brew install —with-plugins grpc It is described here — https://github.com/grpc/homebrew-grpc. Option 2. Hard way — using cmake and make. NOT RECOMMENDED. brew install autoconf automake libtool shtool cmake git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc cd grpc …

Read more

Nice talk about concurrency in Go

Another good talk. It’s not only about channels, but also about atomics and patterns around ti. https://www.youtube.com/watch?v=YEKjSzIwAdA