-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
74 additions
and
18 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 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 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 |
---|---|---|
@@ -1,19 +1,58 @@ | ||
package version | ||
|
||
import ( | ||
"strconv" | ||
"time" | ||
|
||
"github.com/Masterminds/semver" | ||
) | ||
|
||
var ( | ||
// String gets defined by the build system. | ||
String = "0.0.0" | ||
String = "dev" | ||
|
||
// Date indicates the build date. | ||
Date = "00000000" | ||
Date = time.Now().Format("20060102") | ||
) | ||
|
||
// Compiled returns the compile time of this service. | ||
func Compiled() time.Time { | ||
t, _ := time.Parse("20060102", Date) | ||
return t | ||
} | ||
|
||
func GetString() string { | ||
if String == "dev" { | ||
return "0.0.0+dev" | ||
} | ||
parsedVersion, err := semver.NewVersion(String) | ||
// We have no semver version but a commitid | ||
if err != nil { | ||
return String | ||
} | ||
return parsedVersion.String() | ||
} | ||
|
||
func Parsed() *semver.Version { | ||
var versionToParse string | ||
if String == "dev" { | ||
versionToParse = "0.0.0+dev" | ||
} | ||
parsedVersion, err := semver.NewVersion(versionToParse) | ||
// We have no semver version but a commitid | ||
if err != nil { | ||
parsedVersion, _ = semver.NewVersion("0.0.0+" + String) | ||
} | ||
return parsedVersion | ||
} | ||
|
||
func Long() string { | ||
var s string | ||
if Parsed().Metadata() == "" { | ||
s = "-" + Parsed().Prerelease() | ||
} | ||
s = "+" + Parsed().Metadata() | ||
return strconv.FormatInt(Parsed().Major(), 10) + "." + | ||
strconv.FormatInt(Parsed().Minor(), 10) + "." + | ||
strconv.FormatInt(Parsed().Patch(), 10) + "." + "0" + s | ||
} |