How to add a new file to the Go project


I am using the Go plugin for IntelliJ Idea.

I'm not sure how I got my project working like this but I am able to run my Main.go file and it includes all my other files in the project that I can reference. That is perfect.

The problem now is that when I go and create a new "*.go" file it's not included in the IDE build and I get compiled errors wherever I refer to the contents of that file.

How can I fix this?

i think you can set GOPATH in the ~/.bash_profile, e.g. GOPATH=~/code/go export GOPATH

and source ~/.bash_profile or restart the terminal. it will go to effect;

then put *.go or go project related with the main.go under the GOPATH.

finally, main.go will find the *.go.