clarify usage
This commit is contained in:
parent
6dace8255b
commit
d5c2342f76
30
README.md
30
README.md
|
@ -15,17 +15,26 @@ Goals:
|
|||
|
||||
# How it works
|
||||
|
||||
You define the fallback variables in your `main.go`:
|
||||
1. You define the fallback version and version printing in `main.go`:
|
||||
|
||||
```
|
||||
package main
|
||||
|
||||
var (
|
||||
GitRev = "0000000"
|
||||
GitVersion = "v0.0.0-pre0+0000000"
|
||||
GitTimestamp = "0000-00-00T00:00:00+0000"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if (len(os.Args) > 1 && "version" === os.Args[1]) {
|
||||
fmt.Println("My version is", GitVersion, "created at", GitTimestamp)
|
||||
}
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
You `go generate` or `go run git.rootprojects.org/root/go-gitver` to generate `xversion.go`:
|
||||
2. You `go generate` or `go run git.rootprojects.org/root/go-gitver` to generate `xversion.go`:
|
||||
|
||||
```
|
||||
package main
|
||||
|
@ -46,6 +55,17 @@ go run git.rootprojects.org/root/go-gitver
|
|||
cat xversion.go
|
||||
```
|
||||
|
||||
```go
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
package main
|
||||
|
||||
func init() {
|
||||
GitRev = "6dace8255b52e123297a44629bc32c015add310a"
|
||||
GitVersion = "v1.1.4-pre2+g6dace82"
|
||||
GitTimestamp = "2020-07-16T20:48:15-06:00"
|
||||
}
|
||||
```
|
||||
|
||||
<small>**Note**: The file is named `xversion.go` by default so that the
|
||||
generated file's `init()` will come later, and thus take priority, over
|
||||
most other files.</small>
|
||||
|
@ -56,6 +76,12 @@ See `go-gitver`s self-generated version:
|
|||
go run git.rootprojects.org/root/go-gitver version
|
||||
```
|
||||
|
||||
```txt
|
||||
6dace8255b52e123297a44629bc32c015add310a
|
||||
v1.1.4-pre2+g6dace82
|
||||
2020-07-16T20:48:15-06:00
|
||||
```
|
||||
|
||||
# QuickStart
|
||||
|
||||
Add this to the top of your main file, so that it runs with `go generate`:
|
||||
|
|
Loading…
Reference in New Issue