Run go simple app with Jetbrains GoLand IDE

已完成

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

评论操作 固定链接

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?

1
评论操作 固定链接

Vuallla , it is working now as I created configuration via arrow button over main() function.

Thank you very much Daniil

1
评论操作 固定链接

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:

  • Initialize go.mod file: go mod init projectName in the terminal (View | Tool Windows | Terminal).
  • Make sure Go modules integration is enabled under Preferences/Settings | Go | Go Modules.

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.

0
评论操作 固定链接

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

 

0
评论操作 固定链接

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?

0
评论操作 固定链接

yes, I got same error message. 
I'm using GoLand 2020.1 version

0

请先登录再写评论。