Hi all. I'm very new with Go and Gogland. I have a project
Please, help me
First, the general structure of your Go workspace seems to be wrong. You need to make it look more like this:
D:
|-- go_projects
| |-- bin
| |-- pkg
| |-- src
| | |-- FirstSteps
| | | |-- main.go
| | | +-- util
| | | +-- myprinter.go
| | |-- SecondProject
| | |-- ThirdProject
...
Second your import
statement seems to be empty, I have no idea how GoLand works but if you want to use whatever is in your myprinter.go
file, you will need to import the util
package, assuming that the myprinter.go
file declares its package
as util
at the top.
// FirstSteps/main.go
package main
import (
"FirstSteps/util"
)
func main() {
util.MyPrinterFunc()
}
And of course to be able to use anything from util
there first must be something...
// FirstSteps/util/myprinter.go
package util
func MyPrinterFunc() {
// do stuff...
}
Edit: I'm sorry, I didn't actually answer your question initially. You're getting the error Cannot find package 'main'
because of the wrong workspace setup I already mentioned. The Package path
tells GoLand where the package you want to run is relative to the $GOPATH/src
directory. So after you've setup your wrokspace correctly, you should set the Package path
to FirstSteps
since that package's absolute path will be $GOPATH/src/FirstSteps
. If, later, you want to run the util
package you would specify Package path
as FirstSteps/util
for GoLand to be able to find it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With