Debugging Go single file with IntelliJ

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

Debugging Go single file with IntelliJ

问题

我正在尝试在IntelliJ中以调试模式启动一个文件。

这是我的文件内容:

package myPackage

import (
    "fmt"
)

func main() {
    fmt.Println("Hello")
}

我的文件位于文件夹 src/myProject/myPackage 中。

但是当我尝试在IntelliJ中创建一个Go应用程序时,它显示:

"Cannot find Go file with main in 'myProject/myPackage'"

我已经成功做过这个,但是我必须将我的文件放在一个名为 "main" 的包中。
但是现在我的项目正在增长,我需要单独调试我的包。

有什么想法吗?

英文:

I'm trying to launch a file in debug mode in IntelliJ.

Here is my File content :

package myPackage

import (
    "fmt"
)

func main() {
    fmt.Println("Hello")
}

My file is in the folder src/myProject/myPackage

But when I try to create a Go Application in IntelliJ, it says:

"Cannot find Go file with main in 'myProject/myPackage'"

I have already make this work but I had to put my file in a package named "main".
But now my project is growing and I need to Debug my packages separately.

Any Ideas?

答案1

得分: 2

你的应用程序的架构应该像这样:

$Gopath/src/FOLDER_NAME :
|- main.go
|-- my_package/file1.go

在你的file1.go文件中:

package my_package

import "fmt"

func testwork() {

   fmt.Println("it works !!")
}

在你的main.go文件中:

package main

import (
    "fmt"
    "FOLDER_NAME/my_package"
)

func main() {
    my_package.testwork()
}

这样就可以工作了 Debugging Go single file with IntelliJ

英文:

architecture for your app need to be like that :

$Gopath/src/FOLDER_NAME :
|- main.go
|-- my_package/file1.go

in your file1.go

package my_package

import "fmt"

func testwork() {

   fmt.Println("it works !!")
}

in your main.go

package main

import (
    "fmt"
    "FOLDER_NAME/my_package"
)

func main() {
    my_package.testwork()
}

And it will work Debugging Go single file with IntelliJ

答案2

得分: 0

目前,调试仅适用于Go应用程序运行配置。有一个正在进行中的PR来修复这个问题,可以参考这个链接

英文:

Currently debugging works only for Go Application run configurations. There's a PR in progress to fix this, see this.

huangapple
  • 本文由 发表于 2016年3月18日 01:11:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/36067345.html
匿名

发表评论

匿名网友

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

确定