When you start to develop with Go (a.k.a. Golang), one thing you realize is that the generated executable is “big”. A simple HTTP “Hello world” app has a size around 7 MB (depends on the OS and architecture).
For many cases is not a problem, but if you need to transfer it through Internet or to store it in an embedded device… it’s not good.
The Ultimate Packer for eXecutables, UPX, is an executable compressor with very fast decompression time for many of architecture-OS combinations.
The most important architectures are supported: i386, x86_64, arm64, armeb, powerpc, etc.
Regarding OSs, Windows, Linux, BSD and even DOS are supported too.
It’s very easy to install and to use.
In Mac OS X
brew install upx
sudo apt install upx
Deflating our Go app
We use this HTTP Server example in go.
Now we build our app (Mac OS X Catalina with Go 1.14)
go build -o simple-http-server
The size in bytes is: 7.364.228, around 7 MB.
Time to compress it with upx
The magic starts
The resulting executable is around the half size of the original!
Its execution is very fast too.
As you can see it has no complexity. You no longer have any excuses to compress your executables with UPX.
Please, if you liked it, give it a round of applause. And if you want to know more about DevOps, Kubernetes, Docker, etc … follow me :) KR