Skip to content

Commit

Permalink
Handle case of empty GOROOT (#1798)
Browse files Browse the repository at this point in the history
In some situations, such as when using the go-swag Nix package, runtime.GOROOT() will be empty, and RangeFiles will skip all source paths since technically, all paths are prefixed with the empty string.

See also NixOS/nixpkgs#224701

May resolve some cases of #1622.
  • Loading branch information
evan-goode committed Apr 21, 2024
1 parent 0368d7d commit 4c2f8dd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages.go
Expand Up @@ -93,7 +93,7 @@ func (pkgDefs *PackagesDefinitions) RangeFiles(handle func(info *AstFileInfo) er
for _, info := range pkgDefs.files {
// ignore package path prefix with 'vendor' or $GOROOT,
// because the router info of api will not be included these files.
if strings.HasPrefix(info.PackagePath, "vendor") || strings.HasPrefix(info.Path, runtime.GOROOT()) {
if strings.HasPrefix(info.PackagePath, "vendor") || (runtime.GOROOT() != "" && strings.HasPrefix(info.Path, runtime.GOROOT())) {
continue
}
sortedFiles = append(sortedFiles, info)
Expand Down

0 comments on commit 4c2f8dd

Please sign in to comment.