Some tips with Go and Gogland
First, the general structure of your Go workspace seems to be wrong. You need to make it look like this:
D:
|-- go_projects
| |-- bin
| |-- pkg
| |-- src
| | |-- FirstSteps
| | | |-- main.go
| | | +-- util
| | | +-- myprinter.go
| | |-- SecondProject
| | |-- ThirdProject
...
Second, your statement import
appears to be empty, I don't know how goglang works, but if you want to use whatever is in your file myprinter.go
, you will need to import the package util
, assuming the myprinter.go
file declares it package
as util
above.
// FirstSteps/main.go
package main
import (
"FirstSteps/util"
)
func main() {
util.MyPrinterFunc()
}
And, of course, to be able to use any of them util
, there must first be something ...
// FirstSteps/util/myprinter.go
package util
func MyPrinterFunc() {
// do stuff...
}
Edit . Sorry, I didn't actually answer your question. You are getting the error Cannot find package 'main'
because of the wrong workspace setup, which I mentioned earlier. Package path
tells Gogland where the package you want to run is relative to the directory $GOPATH/src
. Therefore, after configuring your wrokspace correctly, you should set Package path
to FirstSteps
, since the absolute path of the package will be $GOPATH/src/FirstSteps
. If you later want to run the package util
, you must specify Package path
how FirstSteps/util
so that it can find it.
source to share