dougou1943 2016-03-17 17:11
浏览 163

使用IntelliJ调试Go单个文件

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?

  • 写回答

2条回答 默认 最新

  • doumang20060820 2016-03-17 21:23
    关注

    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 :)

    评论

报告相同问题?

悬赏问题

  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退