Go Project Setup Using IntelliJ

huangapple go评论87阅读模式
英文:

Go Project Setup Using IntelliJ

问题

刚刚安装了IntelliJ的2016.2.5版本的Community版,并从以下链接安装了Go插件:

https://plugins.jetbrains.com/plugin/5047

我按照向导创建了一个新项目,但是当我运行一个简单的hello.go文件时,在“运行配置”对话框中出现了“主文件无效”的错误。

有人知道如何逐步设置和运行最简单的Go项目吗?

我已经尝试了GoClipse和IntelliJ,对于两者来说,用户文档都非常糟糕。他们总是一样:他们花费了很长时间开发这些东西,但提供的有用文档几乎为零!

谢谢
Graham

英文:

Just installed version 2016.2.5 of the Community edition of IntelliJ and then installed the Go plugin from:

https://plugins.jetbrains.com/plugin/5047

I followed the wizard for creating a new project but when I come to run a simple hello.go file I get a "Main file is invalid" in the "Run Configurations" dialog.

Does anyone know of a step by step guide to setting up and running the simplest of Go projects?

I've tried GoClipse and now IntelliJ and for both the user documentation is absoluetly crap. It's always the same: they spend ages developing this stuff and proide zero useful documentation!

Thanks
Graham

答案1

得分: 4

我在WebStorm中使用插件,相比之前的Go IDE尝试,它有很大的改进。

你遇到的问题很简单。自动生成的代码没有将包设置为main。因此,主文件是无效的。你需要手动将包设置为main,并添加一个名为main的函数。

我确保一个可用的Go开发环境并设置一个新项目的步骤如下:

  • 安装Go
  • 将GOROOT环境变量设置为Go的安装路径,例如/usr/local/go
  • 在你的主文件夹中创建一个go目录,并将GOPATH设置为该目录。
  • 安装IntelliJ和插件
  • $GOPATH/src的子文件夹中创建一个新的Go项目
  • 在IntelliJ中设置Go SDK
  • 创建一个主要的.go文件,确保包名为main,并存在一个main函数。
  • 现在你可以创建一个正确的运行配置。

对我来说,这个方法非常有效,包括调试和运行单元测试。

英文:

I use the plugin with WebStorm, and it is quite an improvement over previous Go IDE attempts.

The issue you run into is quite simple. The auto-generated code does not have the package set to main. For that reason, the main file is invalid. You need to manually set the package to main, and add a function called main.

My steps to ensure a working Go development environment and set up a new project are:

  • Install Go
  • Set GOROOT environment variable to Go installation, e.g. /usr/local/go
  • Create a go directory in your home folder, and set GOPATH to it.
  • Install IntelliJ + plugin
  • Create a new Go project in a subfolder of $GOPATH/src
  • Set the Go SDK in IntelliJ
  • Create a main .go file and make sure package name is main, and a main function exists.
  • Now you can create a proper Run configuration.

For me, this works quite well, including debugging and running unit tests.

huangapple
  • 本文由 发表于 2016年11月22日 22:09:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/40744063.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定