Exploring cross-platform single-file app development using Golang

Photo by Luca Bravo on Unsplash

Exploring cross-platform single-file app development using Golang

ยท

3 min read

To set some context, the app itself will need to provide the following functionality

  • Web app serving few web pages and also serves a REST API.

  • CLI based task/commands to do various tasks including serving the web app.

  • Deploy as a single-file binary which including all the static files embedded within it.

  • Able to use it on all major operating system namely Linux, OSX and Windows

  • SSL access to the web app and API without much hassles.

  • Ability to easily update the app to latest version.

Let us run through each of the above in a bit of detail and will also provide my recommendation based on my knowledge and assessment.

Deploy as a single-file binary which including all the static files embedded within it

  • Evaluated Node.js, Deno, Bun, Python (Pyinstaller), .NET and Golang. All of them produce large binaries except for Go to the size of 50MB to 100MB. You could do some tree shaking to bring down the size a bit but can't reduce much. With Golang, the size was under 10MB which was quite neat as a distributed size. I know Rust also can produce a smaller binary but didn't evaluate it though. Note that the size of the binary is an important factor to run it on low powered machines with less memory.

  • With regards to releasing the binary, you would need to sign the artifacts and checksum them etc. There are several tools available in the respective languages/frameworks. I like goreleaser for this which eases the process or you can create a CI based build and release as well.

  • With regards to embedding the static files like images, JavaScript and CSS files, most of them have varied mechanisms to embed files. Golang starting from v1.16 provides a built-in mechanism to embed files and I really like this as a neat and convenient mechanism to use.

  • All of them have good libraries to wire a good interactive CLI so it is all even-game across the evaluated languages/frameworks. Cobra is a goto library in Golang.

Cross-platform binaries can be built easily in most of the platforms. SSL certs can be easily served by using a library to create LetsEncrypt certificates for use or you could completely ease the process exposing the web app to public by using Cloudflare tunnels as a solution. These are all relatively pretty straight forward to handle. I would love to use CertMagic for Automatic HTTPS using LetsEncrypt.

For self updating, there are many way to accomplish it, use a shell script based update, wire a library which can self-update etc.

For building the web app/API itself, I am more inclined to use a combination of a web framework, htmx for server side interaction and Alpine.js for client side UI interactions. Tailwind CSS for styling. I really like Templ and Gomponents to build the HTML view components in Golang.

I have spent a large amount of my career building productions systems in .NET, Python and Node.js. That said, I am currently starting to appreciate and love Golang more and more as I work with it.

Stay tuned to hear more my experiences on the above topics.

ย