英文:
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()
}
这样就可以工作了
英文:
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
答案2
得分: 0
目前,调试仅适用于Go应用程序运行配置。有一个正在进行中的PR来修复这个问题,可以参考这个链接。
英文:
Currently debugging works only for Go Application run configurations. There's a PR in progress to fix this, see this.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论