Golang插件在Intellij上。库和断点

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

Golang plugin on Intellij. Library and break points

问题

我用Go语言编写我的代码。我在Idea Intellij中使用golang插件构建我的项目。我有一个main包,在main包中导入了不同的包。

这些包在我将路径写入$GOPATH时链接得很好。在Idea Intellij中,它的路径如下所示:

Golang插件在Intellij上。库和断点

现在,我想要:

  1. 无警告地构建我的项目。
  2. 对我的项目进行调试。

第一点。我进行了构建,然后出现了“未指定包”的错误。

Golang插件在Intellij上。库和断点

如果我将包名写为main,警告仍然不会消失:

Golang插件在Intellij上。库和断点

我该怎么办?


第二点。编译成功后,我可以调试部分包,但无法调试另一部分包。例如,我可以调试engine包。该包的路径如下:

/home/INT.PV.KM/urvanov/hedgehogues/distr/mapsfullsearch/src/search/engine/engine.go

但我无法调试下一个文件。

/home/INT.PV.KM/urvanov/hedgehogues/distr/mapsfullsearch/src/search/context.go

Golang插件在Intellij上。库和断点

我无法在这个文件中设置断点:

Golang插件在Intellij上。库和断点

请帮助我解决这些问题。

英文:

I write my code on Go. I build my project in Idea Intellij with plugin for golang. I have a package main. In main import different packages.

import (
	"RF"
	"flag"
	"io"
	"net/http"
	"os"
	"runtime"
	"depot"
	"info"
	"logger"
	"logic"
	"poly"
	"ranker"
	"revgeocoder"
	"search"
	"search/engine"
	"stat"
	"views"
	"fmt"
)

This packages very well linked if I write paths in $GOPATH. In Idea Intellij it makes such way:

Golang插件在Intellij上。库和断点

Now, I want:

  1. Build my project without warning
  2. Debugging my project

First point. I make a 'build' and than I have: "Package is not specified"

Golang插件在Intellij上。库和断点

If I write to Package name main, than warning doesn't disappear:

Golang插件在Intellij上。库和断点

What I can do?


Point number two. The assembly is successful. After that part of package I can debug, another package I cannot debug. For example package engine I can debug. Path to this package:

/home/INT.PV.KM/urvanov/hedgehogues/distr/mapsfullsearch/src/search/engine/engine.go

Next file I cannot debug.

/home/INT.PV.KM/urvanov/hedgehogues/distr/mapsfullsearch/src/search/context.go

Golang插件在Intellij上。库和断点

I cannot set a breaks point in this file:

Golang插件在Intellij上。库和断点

Please, help me with my problems.

答案1

得分: 0

  • 构建我的项目时不要出现警告 -> 你需要使用完整的包名(例如,对于位于GOPATH /home/florin/go 下的包,你需要使用 github.com/dlsniper/demo,对于完整路径 $GOPATH/src/github.com/dlsniper/demo)。或者,你可以使用“运行类型”目录,并将其指向该目录,或者只需使用func main附近的绿色箭头,点击它,选择“运行...”,然后选择“Go应用程序”。

  • 调试我的项目 -> 一旦你使用类型为“Go应用程序”的“运行配置”来运行应用程序,那么要调试它,你只需要使用调试选项而不是运行选项。或者,你可以点击func main附近的绿色箭头,选择“调试...”来调试你的应用程序。
英文:
  • Build my project without warning -> you need to use the full package name (for example you need to use "github.com/dlsniper/demo" for a package under the GOPATH /home/florin/go and full path $GOPATH/src/github.com/dlsniper/demo. Alternatively, you can use the Run Kind directory and point it to the directory or simply just use the green arrow near the func main, click on it, select Run ... and then select Go Application

  • Debugging my project -> once you get your Run Configuration of type Go Application to run the application then to debug it you'll just need to use the Debug option instead of Run. Alternatively, you can click on the green arrow near the func main and choose Debug... to debug your application.

答案2

得分: 0

第一个问题的答案

Go语言中的任何项目都由包组成。除了包之外,没有其他内容。所有的包都位于同一个目录中,这个目录就是项目。其他目录则是库。它们通过环境变量$GOPATH来设置。在IntelliJ IDEA中可以这样设置:

文件->设置:

Golang插件在Intellij上。库和断点

Go语言中有两种类型的库:全局库和本地库。你可以在这里了解更多信息。

在构建时,需要指定要收集的包,并将所有依赖项排列起来。在我的项目中,有n个包。例如,我可以构建mapsfullsearch包。我可以构建mfsimporter包。或者我可以构建任何其他包,其中包含func main() {/*...*/}。只需指定相应的配置即可进行构建。

之后,所有的导入(如果相关的包存在)都会被解析。

Golang插件在Intellij上。库和断点

关于配置,请转到运行->编辑配置...

Golang插件在Intellij上。库和断点

名称:编译文件的名称。
运行类型:构建的类型(文件或包)。
包:与包含main()的目录名称相匹配的包名称。在IDEA IntelliJ中有一个下拉列表。如果你开始输入它的名称,它就会出现。
输出目录:二进制文件所在的目录。
环境变量:环境变量
Go工具参数:编译器的参数
程序参数:程序的参数

关于配置的更多信息可以在这里阅读。

第二个问题的答案

在IDEA中,文件路径可能被错误地指定。在我所提到的问题中,问题与库的路径是通过家目录指定的,家目录用~表示。IDEA不接受这种格式。我没有成功重现这个问题。尽管直到我将项目放在根文件系统中之前,我的项目都无法工作。

英文:

The answer to the first question

Any project in Go consist of packages. There is nothing except for packages. All packages are located in the same directory, which one is project. Other directories are libraries. They set through environment variable $GOPATH. IDEA IntelliJ let make it as:

File->Settings:

Golang插件在Intellij上。库和断点

There are two type of libs in Go: globals and locals. You read about this here.

In the build time is necessary to specify which package we want to gather and line up all the dependencies themselves. In my project, there are n packets. For example, I can build mapsfullsearch package. I can build mfsimporter package. Or I can build any other, in which there is func main () {/*...*/}. To build just specify the appropriate configuration.

After that, all Imports (if relevant packages exist), resolved.

Golang插件在Intellij上。库和断点

About configurations. Go to Run -> Edit Configurations...

Golang插件在Intellij上。库和断点

Name: name of compilled file.
Run kind: which type of building (file or package).
Package: package name that matches the name of the directory in which the main(). There are drop-down list in IDEA IntelliJ. It appears, if you start to write his name.
Output directory: directory where the binary.
Environments: variables of environments
Go Tool arguments: compiler's arguments
Program arguments: program's arguments

For more information about config can be read here.

The answer to the second question

In the IDEA may be poorly specified file path. In that case, to which I referred in her question, the problem was related to the fact that the path to the library is specified via the home directory, which is denoted by ~. IDEA does not perceive such format. Repeat this problem I did not succeed. Although up to the moment until I put the project in the root file system, my project didn't work.

huangapple
  • 本文由 发表于 2016年12月27日 01:15:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/41334268.html
匿名

发表评论

匿名网友

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

确定