Intellij golang build can't find dependencies in the same directory

When I do a build on the file with the main method Intellij can't find a file in the same package and same directory that contains a struct definition.  The editor can find the struct definition because if i Ctrl-click on the struct name it goes to the definition.  Why can't the build / run commands find it?

File:  movietest.go

package main

import ("fmt")

func main() {

var movie Movie = Movie{1, "Test"}
fmt.Println(movie)
}

File: movies.go

package main


type Movie struct {
ID int `json:"id"`
Name string `json:"name"`
}

2
2 comments
Avatar
Permanently deleted user

This command works for me

go run *.go

Actually this will compile all go file and run your main function. So this works well

0
Avatar
Permanently deleted user

But also use go build and go install because using go run *.go will fail if you have *_test.go files (which you should have) and it will silently ignore // +build constraints which will either cause it to fail or behave in an unexpected way depending on how the build tags are used

0

Please sign in to leave a comment.