version.go 554 B

123456789101112131415161718192021222324252627282930313233
  1. package version
  2. import (
  3. "fmt"
  4. "runtime/debug"
  5. )
  6. var version = func() string {
  7. ver := "2.10.1"
  8. if info, ok := debug.ReadBuildInfo(); ok {
  9. var revision string
  10. var modified string
  11. for _, setting := range info.Settings {
  12. switch setting.Key {
  13. case "vcs.revision":
  14. revision = setting.Value[:8]
  15. case "vcs.modified":
  16. if setting.Value == "true" {
  17. modified = "*"
  18. }
  19. }
  20. }
  21. if revision != "" {
  22. return fmt.Sprintf("%v (%v%v)", ver, revision, modified)
  23. }
  24. }
  25. return ver
  26. }()
  27. func GetVersion() string {
  28. return version
  29. }