Ramblings of an aging IT geek
← Ramblings of an aging IT geek
golang

forty lines of go that quietly do their job

A small Go daemon I wrote in an afternoon to replace a flaky cron job, and why the single static binary is the whole point.

A terminal showing Go source code

I replaced a fragile little cron job this week with a tiny Go daemon, and the satisfying part wasn't the code, it was the deploy. One static binary, scp it up, drop in a systemd unit, done. No runtime to install, no interpreter version to match, no dependencies to apt-get. The thing that took the afternoon was deciding what it should do; the thing that usually eats the afternoon, getting it to run on the box, took about two minutes.

The daemon watches a directory, debounces the filesystem events because editors love to fire six of them per save, and pokes a webhook when something settles. The whole core is a time.Timer you keep resetting on each event, so you only fire once the noise stops. Go's standard library had everything I needed: fsnotify for the watch, net/http for the poke, and signal.Notify to shut down cleanly on SIGTERM so systemd doesn't have to kill it.

What I keep coming back to is the cross-compile. GOOS=linux GOARCH=amd64 go build on my laptop produces the exact artefact that runs on the server, and I can prove it works before it ever leaves my machine. The old cron job failed silently for a week once because a Python dependency drifted on the host. This won't, because there's nothing on the host for it to drift against. Boring, single-purpose, and it's been running without a peep. That's the whole review.