Created
November 3, 2014 22:52
-
-
Save peterhellberg/1765ba74860ebf1df817 to your computer and use it in GitHub Desktop.
Set build date using the Go linker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
go build -ldflags "-X main.buildDate `date -u +%Y-%m-%d.%H%M%S`" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
var buildDate string | |
func main() { | |
fmt.Println(buildDate) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Go linker has the command line option
-X
used to set the value of an otherwise uninitialized string variable.