Matt Mohan

Define at compile

1 min read

To define a constant at build time you can use a compiler flag like: go build -ldflags="-X 'package_path.key=value'" and then consume it like

package package_path

var (
  key = "default_value"
)

func main() {
  fmt.println(key)
}

Matt Mohan

I’m Matt, a software engineer based just outside of Toronto, Canada. This blog is mostly an excuse to (re)build sites with different web tooling and compare their relative merits