golang

Containerized development workflow using remote gopls server

05 Nov 2019 - 4 minute read
categories: golang notes tags: golang docker

If your CGO development toolchain depends on external dependencies such as system libraries, or you want to develop on an older version of go while having a different version on your host, you can use a docker container and mount the source from your host machine and build the project inside the container. This can enable us to have a consistent development environment across various developers and their host systems without having to modify system libraries.

Setting SO_REUSEPORT and similar socket options in Go 1.11

08 Jan 2019 - 2 minute read
categories: notes golang tags: golang networking

Go recently introduced a heavily requested feature that allows programmers to set socket options before accepting and creating connections. You can find a mention of this in Go 1.11 Release Notes. Although, not many have written on this and implementing this is a bit confusing due to a change in the way one has to implement this. So I decided to share this with others who might be interested in using this feature.

Functional Options for testing without mocks in Golang

30 Jul 2018 - 3 minute read
categories: notes golang tags: api golang notes

Suppose you have a HTTP request to be sent but don’t care about the result or errors. This request is sent through a function which is usually called inside a goroutine and is not in any way a core aspect of your main logic. The only important part is forming the actual request and the payload. When you wrote this function, you did not write tests as it would be a pain to make the function return something and check it.