简体   繁体   中英

Golang plugin on Intellij. Library and break points

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:

包的路径

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"

未指定套件

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

找不到包<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:

/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

目录树

I cannot set a breaks point in this file:

断点

Please, help me with my problems.

  • 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.

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:

外包装

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.

我的项目的结构

About configurations. Go to Run -> Edit 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM