2

I am not sure if this behavior is intended, but GoLand appears to NOT auto-import local project packages when referenced.

GoLand has intellisense for the package and package methods. However, after adding the method for a local package, GoLand just complains that it is an "unresolved reference". Until I manually import the package myself.

I have all of my import optimization settings enabled. GoLand auto-imports ALL github and system packages, just not my local project packages.

Is there any way to enable auto-import for local packages? Or must I manually import them myself?

Thank you

enter image description here

Not auto-importing

Manually imported

Fletcher
  • 109
  • 1
  • 8
  • 1
    You cannot use relative paths in GOPATH. Step through [How to Write Go Code](https://golang.org/doc/code.html) for complete examples – JimB Feb 28 '19 at 20:01

1 Answers1

3

It's not a good practice to use local imports this way. Instead, link to the package through your GOPATH, i.e. github.com/your_github_username/your_project_dir/utilities.

Assuming project directory:

$GOPATH/
  |
  src/
   |
   github.com/
     |
     your_github_username/
          |
          your_project_dir/
              |utilities
          main.go

project: github.com/your_github_username/your_project_dir

package: github.com/your_github_username/your_project_dir/utilities

Following this standard your local package should import without issue.

jonroethke
  • 1,152
  • 2
  • 8
  • 16