I learned a neat trick in Go

Arpit Bhayani

Arpit Bhayani

Mar 11, 2025 • 1 min read


I learned a neat trick in Go.

I have a VERSION file at the project root holding the current version number of DiceDB. I want to use this version everywhere I am referring to the version

  1. when the server runs
  2. version subcommand
  3. tests, and
  4. even baked in the binary

Instead of duplicating the version across the codebase, here’s an interesting hack using the current caller (check screenshot).

This, combined with the build-time injection of version variables, makes sure that even the binary has access to this version number without having to ship the VERSION file everywhere [that’s impactical anyways].

Arpit Bhayani

Principal Engineer II at Razorpay - building Agent Studio, Ex-staff engg at GCP Memorystore & Dataproc, Creator of DiceDB, ex-Amazon Fast Data, ex-Director of Engg. SRE and Data Engineering at Unacademy. I spark engineering curiosity through my no-fluff engineering videos on YouTube and my courses