The Powerful Interface in Go — Inspired by a Simple Todo CLI Tool

I am building an Todo CLI tool recently and used Go’s powerful interface to achieve better formatting. Previously my cli looks like: $ ./todo -list Another ToDo item Improve usage Improve output And the code looks like: l := &todo.List{} switch { case *list: for _, t := range *l { if !t.Done { fmt.Println(t.Task) } } But I don’t just want to print out the items I put inside the list, I want to items printed out with number and a mark “X” to indicate if the item was completed or not....

November 11, 2023 · 4 min · 812 words · David Lee

Rust or Go

This topic has bothered me for a while as a Go developer, and I’ve been learning Rust for a while and have this article written as part of my research. Rust and Go are both modern programming languages that have gained popularity for their focus on performance and reliability. However, they have different design philosophies and use cases. Here are some key differences: Memory Safety: Rust has a unique feature called ownership with a borrow checker that ensures memory safety without a garbage collector....

November 7, 2023 · 4 min · 732 words · David Lee

Demystify Unit Tests

There was a time I argue within my dev team what a unit test is. Many devs write unit tests with a real DB interaction or with other dependecies but they still call it unit tests. I strongly agree that when we want to test interactions, we should NOT mock the DB with 3rd party dependencies like “github.com/DATA-DOG/go-sqlmock”: When we want to test interactions, we should and always use real DB....

October 3, 2023 · 4 min · 840 words · David Lee

My Tricks on Outpacing an Entire Team in Tests

I don’t want to waste your time and let’s hit the point, this article mainly discusses about how to speed up your test experience with mocks. below are my tricks used in generate.go file: This is the package we need to install: go install github.com/vektra/mockery/v2@latest Mockery provides the ability to easily generate mocks for Golang interfaces. Running go generate will generate mocks for all interfaces within the directories: The above example shows that interfaces in application....

October 3, 2023 · 2 min · 421 words · David Lee

Nginx as Reverse Proxy in Microservices

Developers might find topics related to DevOps quite annoying, but once you master this skill, and you can be invincible. Just like we cannot skip Docker, let’s challenge Nginx heads on. Setting up Nginx as a reserve proxy might not be that troublesome as you expect. Check below the nginx.conf file: It’s quite easy to understand above code. The server listens on port 8080 and proxies requests to various upstream servers based on the URL path....

October 3, 2023 · 4 min · 728 words · David Lee