version.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package main
  2. import (
  3. "bytes"
  4. "runtime"
  5. "text/template"
  6. )
  7. var (
  8. // GitCommit is git commit
  9. GitCommit = "library-import"
  10. // Version is version
  11. Version = "library-import"
  12. // BuildTime is BuildTime
  13. BuildTime = "library-import"
  14. // Channel is Channel
  15. Channel = "library-import"
  16. )
  17. // VersionOptions include version
  18. type VersionOptions struct {
  19. GitCommit string
  20. Version string
  21. BuildTime string
  22. GoVersion string
  23. Os string
  24. Arch string
  25. Channel string
  26. }
  27. var versionTemplate = ` Version: {{.Version}}
  28. Go version: {{.GoVersion}}
  29. Git commit: {{.GitCommit}}
  30. Built: {{.BuildTime}}
  31. OS/Arch: {{.Os}}/{{.Arch}}
  32. Channel: {{.Channel}}
  33. `
  34. func getVersion() string {
  35. var doc bytes.Buffer
  36. vo := VersionOptions{
  37. GitCommit: GitCommit,
  38. Version: Version,
  39. BuildTime: BuildTime,
  40. GoVersion: runtime.Version(),
  41. Os: runtime.GOOS,
  42. Arch: runtime.GOARCH,
  43. Channel: Channel,
  44. }
  45. tmpl, _ := template.New("version").Parse(versionTemplate)
  46. tmpl.Execute(&doc, vo)
  47. return doc.String()
  48. }