2016-12-26 17:15

Intellij上的Golang插件。 库和断点

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 (

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

Path to packages

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"

Package is not specified

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

Cannot find package <code>main</code>

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:


Next file I cannot debug.


Tree of catalog

I cannot set a breaks point in this file:

Break point

Please, help me with my problems.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • duan7772 duan7772 5年前

    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:


    Outer packages

    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.

    Struct of my project

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

    Settings of configurations

    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.

    点赞 评论 复制链接分享
  • douyin4875 douyin4875 5年前
    • 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.
    点赞 评论 复制链接分享