In my post Getting a --version flag for Cobra CLIs in Go, built with GoReleaser I wanted to add a --version flag to my Go command-line tools.
However, I noted that this solution only works when using GoReleaser, and doesn't work when built from source.
Fortunately this week Carla...
TL;DR: Just import github.com/carlmjohnson/versioninfo and use versioninfo.Revision to automatically include a Git hash in your Go application.
Curious how it works? Want to make your own version info package? Read on.
In previous blog posts, I’ve written about how you can inc...
A book I was recently reading mentioned a
mathematical curiosity I haven't seen before - Tupper's self-referential
formula.
There are some resources about it online, but this post is my attempt to
explain how it works - along with an interactive implementation you can try
in the...
One of the things I really love about Go's structural typing is how interfaces work. It took a bit of getting used to it coming from Java, but I really enjoy the fact that just by implementing a method, you can call it a day.
For instance, if you want to implement an HTTP server,...
Let's say that we have three binaries, and we want to detect the Operating Systems and CPU architectures in use:
ls
dmd
dmd-darwin
dmd.exe
url
If we run this through the file command, we can see the following information:
$ file dmd
dmd: ELF 64-bit LSB executable, x86-64, version...
I've recently been writing some HTTP servers using Go's net/http package, and found that trying to add a 404 handler - by default - wasn't super straightforward.
As per the net/http documentation:
Note that since a pattern ending in a slash names a rooted subtree, the pattern &q...
Fuzz testing is Go’s clever way of generating new test inputs that you
didn’t think of—and that may flush out some hidden bugs. Stand by for
things to get a little fuzzy!