12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package main
- import (
- "fmt"
- "log"
- "os/exec"
- "strings"
- )
- // 1.0.0-dev
- const (
- VERSION_MAJ = 1
- VERSION_MIN = 0
- VERSION_PAT = 0
- VERSION_TAG = "dev"
- )
- func GitVersion() string {
- var (
- cmd *exec.Cmd
- err error
- stdout []byte
- )
- cmd = exec.Command("git", "describe",
- "--abbrev=8",
- "--long",
- "--tags",
- "--dirty",
- "--always",
- "--match",
- "v[0-9]*")
- stdout, err = cmd.Output()
- if err != nil {
- log.Println("Err (GitVersion):", err)
- return ""
- }
- return strings.TrimSpace(string(stdout))
- }
- func Version() string {
- var hash string = GitVersion()
- if hash != "" {
- return fmt.Sprintf("%d.%d.%d-%s#%s", VERSION_MAJ, VERSION_MIN, VERSION_PAT, VERSION_TAG, hash)
- }
- return fmt.Sprintf("%d.%d.%d-%s", VERSION_MAJ, VERSION_MIN, VERSION_PAT, VERSION_TAG)
- }
|