0

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?

Harmelodic
  • 5,682
  • 1
  • 28
  • 31
Jérémy Bricout
  • 159
  • 1
  • 3
  • 7
  • 1
    [Read this](https://golang.org/doc/code.html) and troubleshoot. It's likely that this question is a near duplicate of [this question](http://stackoverflow.com/questions/15049903/how-to-use-custom-packages-in-golang) – Harmelodic Mar 17 '16 at 17:31

2 Answers2

2

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

Fantasim
  • 876
  • 1
  • 12
  • 32
  • Thanks, it helps a lot for understanding the concept of executing the application. But I want to proceed unit tests and avoid the usage of the "main way". I want to use my *_test.go associated file and make debugging and breakpoints work on my IntelliJ. Have you any idea ? Thanks – Jérémy Bricout Mar 18 '16 at 08:06
  • Have u check that ? https://github.com/go-lang-plugin-org/go-lang-idea-plugin/wiki/Documentation it speak about debuging at end of doc – Fantasim Mar 18 '16 at 10:17
0

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

dlsniper
  • 7,188
  • 1
  • 35
  • 44