One of the most requested features for my terminal user interface library tview
(now at 8.6K stars, which is still mind-boggling to me) was a multi-line text editor. Before starting to work on this UI component, I collected my users’ requirements for it. They basically boiled down to this:
Mocking APIs in Go - An Alternative Approach
It’s fairly common that one has to write unit tests for applications that access external systems. We don’t want to forgo the advantages of unit tests for these applications. So we need to find a way to run them self-contained, without depending on external systems.
Imagine we have a function which saves a user’s password in the database:
Read more...Word wrapping in Go
Convert an Image to Grayscale in 2 Lines of Golang
If you turn to Google on how to convert an image (e.g. a JPEG) to grayscale, almost all solutions you will find will cycle through all pixels individually to convert them to a luminance value:
Read more...IATA SSIM Flight Schedule Parser
This post likely doesn’t affect most readers of this blog. But since I also write to document my work, this announcement will go here.
I implemented a new commercial software tool which can read IATA SSIM Flight Schedule files (Chapter 7). SSIM files follow a sophisticated fixed-width format and are used to describe an airline’s flight schedule over a specific period of time (usually 365 days into the future). These files are used to exchange schedule information among a large number of airline systems, some of which include:
Read more...How to Count the Characters in a String (Unicode)
You would think that maintaining a mildly popular package such as tview
would consist mostly of adding cool new features, maybe with the odd bugfixing sprinkled in. You would be wrong. If I had to guess, I would say 70% of my work on it was dedicated to making Unicode characters work. It’s all very simple when you just have to support the English language. But with the first requests for Chinese, Thai, Arabic, or emoji support, I realized I was in for a lot of trouble. (And I dread the day when users will ask for Hebrew which is written from right to left.)
Golang: Append Modifies Underlying Slices
Even after four years of programming in Go, there are still things I didn’t know about the language itself. The following example illustrates behaviour that surprised me. My (false) assumptions actually led to a bug which was very difficult to find as it happened only rarely and repeated reviews of the code didn’t turn up anything unusual. Here it is:
Read more...My Go Package Reaches 1.4K Stars on GitHub
Terminal-Based User Interfaces in Go
My Gopher Academy Blog Post on Web Sessions and User Workflows
I’ve released two new Golang packages on GitHub: github.com/rivo/sessions and github.com/rivo/users. They will help you write web apps in Golang.
Read more...