Get Correct Module Name via Trie-Style Structure
Go language supports to put modules under a VCS, such as github. Usually, one git repo contains one go module and multiple packages under this module. However, this is not always correct because Go allows you to put multiple modules under the same module, and Go helps to find these modules via its path. A typical example is repository go.opentelemetry.io/otel
, which contains huge amount of modules.
In my real senario, given a list of used modules parsing from go.mod
, and a package name retrieving from import declaration, I want to know which module does this package belong to. strings.Contain
isn't help at all because module paths have overlapped a lot.