Search code examples
goimportpathrelative-path

Check if Go import path is local


Is there a programmatic way (other than manual path parsing) to check whether an import path in Go is local? I can do it manually, but I'd prefer to avoid a buggy implementation.


Solution

  • Use build.IsLocalImport to determine if an import path is local.

    IsLocalImport reports whether the import path is a local import path, like ".", "..", "./foo", or "../foo".