Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sarama

import (
"reflect"
"runtime/debug"
"sync"
)
Expand All @@ -12,9 +13,18 @@ var (

func version() string {
vOnce.Do(func() {
// Determine our package name without hardcoding a string
type getPackageName struct{}
thisPackagePath := reflect.TypeFor[getPackageName]().PkgPath()

bi, ok := debug.ReadBuildInfo()
if ok {
v = bi.Main.Version
for _, dep := range bi.Deps {
if dep.Path == thisPackagePath {
v = dep.Version
Comment thread
adamdecaf marked this conversation as resolved.
break
}
}
}
if v == "" || v == "(devel)" {
// if we can't read a go module version then they're using a git
Expand Down
Loading