2021-07-10 17:11:37 +00:00
|
|
|
# Using the `main.version` ldflag
|
|
|
|
|
2022-09-27 12:04:47 -03:00
|
|
|
By default, GoReleaser will set the following 3 _ldflags_:
|
2021-07-10 17:11:37 +00:00
|
|
|
|
2022-09-27 12:04:47 -03:00
|
|
|
- `main.version`: Current Git tag (the `v` prefix is stripped) or the name of
|
|
|
|
the snapshot, if you're using the `--snapshot` flag
|
2021-07-10 17:11:37 +00:00
|
|
|
- `main.commit`: Current git commit SHA
|
2022-09-27 12:04:47 -03:00
|
|
|
- `main.date`: Date in the
|
|
|
|
[RFC3339](https://golang.org/pkg/time/#pkg-constants) format
|
2021-07-10 17:11:37 +00:00
|
|
|
|
|
|
|
You can use them in your `main.go` file to print more build details:
|
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
var (
|
|
|
|
version = "dev"
|
|
|
|
commit = "none"
|
|
|
|
date = "unknown"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2022-09-27 12:04:47 -03:00
|
|
|
fmt.Printf("my app %s, commit %s, built at %s", version, commit, date)
|
2021-07-10 17:11:37 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-09-27 12:04:47 -03:00
|
|
|
You can override this by changing the `ldflags` option in the
|
|
|
|
[`build` section](/customization/build/).
|