Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
Created November 3, 2014 22:52
Show Gist options
  • Save peterhellberg/1765ba74860ebf1df817 to your computer and use it in GitHub Desktop.
Save peterhellberg/1765ba74860ebf1df817 to your computer and use it in GitHub Desktop.
Set build date using the Go linker
#!/bin/bash
go build -ldflags "-X main.buildDate `date -u +%Y-%m-%d.%H%M%S`"
package main
import "fmt"
var buildDate string
func main() {
fmt.Println(buildDate)
}
@peterhellberg
Copy link
Author

The Go linker has the command line option -X used to set the value of an otherwise uninitialized string variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment