Still doesn't work for devel builds of main however.
https://github.com/anacrolix/torrent/issues/889#issuecomment-
1891242553
"fmt"
"reflect"
"runtime/debug"
+ "strings"
)
var (
if buildInfo, ok := debug.ReadBuildInfo(); ok {
mainPath = buildInfo.Main.Path
mainVersion = buildInfo.Main.Version
+ thisModule := ""
// Note that if the main module is the same as this module, we get a version of "(devel)".
for _, dep := range append(buildInfo.Deps, &buildInfo.Main) {
- if dep.Path == thisPkg {
+ if strings.HasPrefix(thisPkg, dep.Path) && len(dep.Path) >= len(thisModule) {
+ thisModule = dep.Path
torrentVersion = dep.Version
}
}