golang

Why group and order imports in Go?

Posted on 09 March 2022 - 1 min read

Why should I group and order imports in Go? [Read more]

Tagged with: go, conventions, import, best-practices, golang

Pre-commit hooks with Go

Posted on 29 August 2021 - 1 min read

Git hook scripts are becoming more and more popular. We run our hooks on every commit to automatically point out some simple issues in code before submission to code review. By pointing out these issues in this early phase, it allows a faster feedback loop than waiting for CI. [Read more]

Tagged with: go, golang, pre-commit, hooks, git, git-hook

Dependency injection with Go

Posted on 25 May 2021 - 3 min read

One of the advantages of using Go is that programmers can quickly onboard and start writing code. And I've seen a colleague who was able to read Go code in the first day and submit code change for review in the third day. Because the language is simple and straightforward, Go programmers can start writing production code without much knowledge about OOP or design patterns like dependency injection. In this post, we'll discuss the importance of dependency injection and how to apply it in Go effectively. [Read more]

Tagged with: go, golang, dependency-injection, dependency-inversion

Create a code generator with protoc

Posted on 08 May 2021 - 2 min read

If your system happens to have a microservices architecture, you may find it repetitive to scaffold new services or to add new endpoints. In such scenarios, Protocol Buffer emerges to be an excellent choice for writing API contracts and generating code. However, you sometimes may want to add a custom code but you're not sure how to to that. Actually, it's quite simple with `protoc` though. In this post, we will walk through how to create a code generator with protoc. [Read more]

Tagged with: go, golang, protoc, protobuf, code-generator, protocol-buffer

Safely Use Go Context to Pass Data

Posted on 10 April 2021 - 2 min read

Go context is an excellent and controversial feature. It's handy to pass data to deep level functions without exploding the complexity of codes. However, its convenience could also be a source of bugs in your program. This post will discuss one common problem when using Go context. [Read more]

Tagged with: go, golang, context

Bong Nguyen © 2016 - 2022