Run go simple app with Jetbrains GoLand IDE
Completed
I've just started learning GO. Ok, I've some weird issue and did not figure out how to fix it. I have 2 go file. one is main.go and second is state.go and they are both in same package called main. In state.go file I defined simple function printHello, which then I'm calling it in main.go.
state.go
package main
import "fmt"
func printHello() {
fmt.Println("Hello World!")
}
main.go
package main
func main() {
printHello()
}
When I run it in cmd with command: go run main.go state.go it works fine, but in GoLand IDE it didn't. I tried to build it changed Run Kind to Directory, but without success. Also attached image for more clarification
Please sign in to leave a comment.
There are a few ways to manage your code dependencies: Go Modules & GOPATH (will be deprecated soon). I see your project directory doesn't contain go.mod file, so I suppose that you get started with GOPATH. If so, make sure that go env points GOPATH to your current project directory or use Go Modules instead.
I highly recommend starting with Go Modules and you can follow the steps:
After that, you should be able to run your code inside the IDE with Run kind | Package/Directory (Run | Edit Configurations).
Feel free to provide a bit more details after these steps if it doesn't help.
First step: I just crated Go.mod file
Actually I don't know, what it is use for.
second step.
and this is gopath also
Please see https://go.dev/blog/using-go-modules for details about Go Modules.
Do you get the same error after these steps? What version of GoLand are you using?
yes, I got same error message.
I'm using GoLand 2020.1 version
Could you please update GoLand to the latest available version, remove the configuration from Run | Edit Configurations and create a new one via the gutter icon over main() function?
Vuallla , it is working now as I created configuration via arrow button over main() function.
Thank you very much Daniil