I love CLI applications. They are lightweight, no-dependency, and consume fewer resources. However, building an application for the terminal from scratch is far from easy.
Fortunately, we can always simplify the task with tools or libraries. In this tutorial, I’ll show you how to build a terminal-based dashboard in less than 300 lines of Golang source code by leveraging a great terminal library, termui.
We have a web application that serves millions of users a day. And we want to monitor the real-time memory consumption (and GC) of this application.
If you visit Rob Pike’s homepage on Twitter, you may notice that his bio contains only one sentence: Ed Is the Standard Text Editor.
There must be something special about Ed as a text editor. This article will explain what makes it so special.
ed is a line editor on Unix systems. When it comes to editors, many people may first think of
vi but in fact,
ed is its “grandfather”.
In the previous story, I generate a static website with Hugo. Today, let me explain how to host this website on IPFS in detail. Hope this story could help you a bit.
To quote the official website, IPFS is “A peer-to-peer hypermedia. It is designed to make the web faster, safer, and more open.”
It’s unintuitive at first glance, but reiterating its goal should help in understanding this technology.
Its goal is to replace the HTTP protocol and build a distributed and better Web. It defines all the protocols that will be used in the distributed Web. …
Hugo is an interesting static website generator. It is efficient, concise, and powerful. I’ll show you the pleasant journey of building a website from scratch with it.
Hugo is very easy to learn, so I believe anyone with a basic technical background could quickly create a beautiful static website with Hugo.
Recently, I was learning IPFS and found this stuff to be perfect for hosting static websites since it is content-centric, distributed, tamper-proof, censorship-resistant.
That being said, why not build a Blog on IPFS for fun? …
Finite-State Machine(FSM) is an essential concept of computation. We can find many behaviors of FSM in our real lives such as vending machines, elevators, traffic lights, etc.
FSM-based programming is also a powerful tool to model complicated state transitions, it could significantly simplify our program.
A finite-state machine (FSM) or simply a state machine, is a mathematical model of computation. It is an abstract machine that can be in exactly one of a finite number of states at any given time. …
This is the index of the series of articles about Micro.
Programmers don’t like manual work. They always tend to find the most effective tool to deal with ad hoc jobs.
When there isn’t a tool fit for the job, most of them will turn to write a script (or program) for it. After all, we’re programmers.
But my advice is to consider using old-good CLI tools before writing a script. This is especially true when tackling text-based data files. There’re already many built-in tools in the Unix/Linux ecosystem to manipulate text since Unix has a tradition of preferring text over other data formats.
A suggestion for those programmers who have MS-Windows background only: seriously consider learning Unix even at a basic level, then a new world will be opened to you. …
How to pass structural error information between services in Go Micro v2
In a distributed system, it is a common case that an error is produced by one service then returned to another one. It will be great if we could pass all structural errors across services without losing detail information.
github.com/micro/go-micro/v2/errors package from Micro v2 serves exactly this purpose. Let me quote the introduction from the official documentation:
Go Micro provides abstractions and types for most things that occur in a distributed system including errors. …
Unit testing DB-interactive codes is not easy. It becomes harder when an ORM library like GORM is involved.
Theoretically, we could mock all the interfaces of
database/sql/driver (such as Conn and Driver) with the great mock tool GoMock. However, we still need a lot of manual work to complete this kind of testing even with the help of GoMock.
The good news is Sqlmock could solve the aforementioned problem. As declared by its official website, it’s an “Sql mock driver for golang to test database interactions.”
This article will show you how to unit test a simple blog application with Sqlmock. The application is backed with PostgreSQL and uses GORM to simplify O-R mapping. …
Unit testing of codes with dependencies is always a pain. It gets even worse when the dependencies are external resources such as databases, networks, and files.
An intuitive solution to this is to create an isolated environment providing all these external resources, and then run test cases in it. But then they’re not unit tests anymore; they’re integration tests.
Don’t get me wrong. Integration tests have their value and we definitely need them. But they aren’t suitable for running against every code change for three reasons: