version.go 463 B

123456789101112131415161718192021222324252627
  1. package sarama
  2. import (
  3. "runtime/debug"
  4. "sync"
  5. )
  6. var (
  7. v string
  8. vOnce sync.Once
  9. )
  10. func version() string {
  11. vOnce.Do(func() {
  12. bi, ok := debug.ReadBuildInfo()
  13. if ok {
  14. v = bi.Main.Version
  15. }
  16. if v == "" || v == "(devel)" {
  17. // if we can't read a go module version then they're using a git
  18. // clone or vendored module so all we can do is report "dev" for
  19. // the version to make a valid ApiVersions request
  20. v = "dev"
  21. }
  22. })
  23. return v
  24. }