go build -ldflags="-X main.version=1.0.0 -X main.commitHash=abc123 -X main.buildDate=$(date)"
In the Go code:
go
Copy code
package main
import "fmt"
var (
version string
commitHash string
buildDate string
)
func main() {
fmt.Printf("Version: %s\nCommit Hash: %s\nBuild Date: %s\n", version, commitHash, buildDate)
}
//
go build specify output binary
go build -o ./bin/mybinary
// Go build main.go is in another folder
go build -o ./bin/mybinary /folder/main.go
No comments:
Post a Comment