-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create version package, so it can be used outside of main
- Loading branch information
1 parent
f0b33d9
commit 105c32a
Showing
10 changed files
with
92 additions
and
61 deletions.
There are no files selected for viewing
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
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// +build !release | ||
|
||
package version | ||
|
||
var ( | ||
builtAt, gitCommit, gitTag string | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// +build release | ||
|
||
package version | ||
|
||
// This file was generated by release_generate.go; DO NOT EDIT. | ||
|
||
// Values of builtAt and gitCommit will be set by the linker. | ||
var builtAt = "" | ||
var gitCommit = "" | ||
var gitTag = "0.1.11" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// +build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
|
||
. "github.com/dave/jennifer/jen" | ||
) | ||
|
||
func main() { | ||
f := NewFile("version") | ||
|
||
f.Comment("This file was generated by release_generate.go; DO NOT EDIT.") | ||
f.Line() | ||
|
||
f.Comment("Values of builtAt and gitCommit will be set by the linker.") | ||
f.Var().Id("builtAt").Op("=").Lit("") | ||
f.Var().Id("gitCommit").Op("=").Lit("") | ||
|
||
gitTag := os.Getenv("RELEASE_GIT_TAG") | ||
f.Var().Id("gitTag").Op("=").Lit(gitTag) | ||
|
||
buf := &bytes.Buffer{} | ||
if _, err := buf.WriteString("// +build release\n\n"); err != nil { | ||
log.Fatal(err.Error()) | ||
} | ||
if err := f.Render(buf); err != nil { | ||
log.Fatal(err.Error()) | ||
} | ||
if err := ioutil.WriteFile("release.go", buf.Bytes(), 0644); err != nil { | ||
log.Fatal(err.Error()) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package version | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
//go:generate go run ./release_generate.go | ||
|
||
// Info hold version information | ||
type Info struct { | ||
BuiltAt string | ||
GitCommit string `json:",omitempty"` | ||
GitTag string `json:",omitempty"` | ||
} | ||
|
||
var info = Info{ | ||
BuiltAt: builtAt, | ||
GitCommit: gitCommit, | ||
GitTag: gitTag, | ||
} | ||
|
||
// Get return version Info struct | ||
func Get() Info { return info } | ||
|
||
// String return version info as JSON | ||
func String() string { | ||
if data, err := json.Marshal(info); err == nil { | ||
return string(data) | ||
} | ||
return "" | ||
} |