Skip to content

Commit 4c2f8dd

Browse files
authored
Handle case of empty GOROOT (#1798)
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.
1 parent 0368d7d commit 4c2f8dd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (pkgDefs *PackagesDefinitions) RangeFiles(handle func(info *AstFileInfo) er
9393
for _, info := range pkgDefs.files {
9494
// ignore package path prefix with 'vendor' or $GOROOT,
9595
// because the router info of api will not be included these files.
96-
if strings.HasPrefix(info.PackagePath, "vendor") || strings.HasPrefix(info.Path, runtime.GOROOT()) {
96+
if strings.HasPrefix(info.PackagePath, "vendor") || (runtime.GOROOT() != "" && strings.HasPrefix(info.Path, runtime.GOROOT())) {
9797
continue
9898
}
9999
sortedFiles = append(sortedFiles, info)

0 commit comments

Comments
 (0)