Refactored Telegram

It’s all just ones and zeros under the cover

Setting Go Variables During Build

Like many others, there are occasions when and I want to store the value from the environment, like the current build number or Git commit hash, in the source code of a software package so that I can display it on startup or when invoked with a command line switch. This information is only available during the build phase of the application, so something will need to be added to the build process to inject this value once it is known. This is relatively easy to do in C by using the -D switch to the compiler to declare the value as a macro. Even in Java this can be done using Maven resource filtering.

However, I was unaware of how this was done in Go. To date, I have been using a simple form of code generation that involved passing sed over a source file with a dummy string constant. sed would be configured to replace that constant with the version number or Git hash prior to the Go application being built. This worked, but it was a little bit inelegant.

I have since learnt, via this Stack Overflow answer, that it’s possible to set the initial value of a Go variable directly from the build command. The process is not as nice as it could be, as it involves actually setting flags to the linker, but it works reasonably well and is much nicer than doing things with sed .

Read more →

Posts Only RSS Feed in Hugo

This blog is a static website generated using Hugo. Like most other static website generators, Hugo provides a lot of features out of the box, one of them being the generation of RSS feeds. I wanted to add a link to an RSS feed of the blog posts to the nav-bar. After trying the /index.xml, I noticed that it included entries for the static pages that are not themselves posts, like the About page.

I wanted to exclude these static pages them from the RSS feed. Here is how I did it.

Read more →

Hello World

Hello, and welcome to Refactored Telegram, a blog about my adventures in software development.

I have been meaning to start a blog dedicated to working in software for a while. As a professional developer and someone who builds side projects in his spare time, I occasionally write on the topic in my personal blog. But it felt a little strange interleaving my thoughts on the subject alongside my day to day blog entries. I felt it was necessary to put together a separate blog for posts that relates to my professional and personal work, which is the reason for the existence of this blog.

Read more →