P
P
pustserg2016-08-05 14:13:38
go
pustserg, 2016-08-05 14:13:38

Multi-file Golang project in Intellij IDEA. What about imports?

Good afternoon, faced such problem. Defined struct in another file (package same main), but IDEA with Go plugin ( https://github.com/go-lang-plugin-org/go-lang-idea... ) refuses to start the project.
The project structure is such
a Struct2.go file

package main

type Struct2 struct {
  Field2 string
}

main.go file
package main

import (
  "fmt"
)

func main() {
  s1 := struct1{field1: "field1"}
  fmt.Println(s1)
  s2 := Struct2{Field2: "field2"}
  fmt.Println(s2)
}


type struct1 struct {
  field1 string
}

When running in IDEA, I get the following error
./main.go:10: undefined: Struct2
When this LiteIDE starts up normally. In the console, too, go build builds everything and the binary runs without problems.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pustserg, 2016-08-05
@pustserg

So I sort of figured it out, thanks to Nikita for suggesting the idea.
Here in the settings there should be a launch type not File but Package

N
Nikita, 2016-08-05
@bitver

I don’t know what you have with IDEA, but you are trying to do something likego build main.go , but you just need to go build, well, tests, design things, etc., etc. Just set up the builder, in such IDEs it should be extremely simple.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question