In my GOPATH I have something like this:
/bin/
/pkg/
/src/
/src/my_prog/
/src/my_prog/main.go
/src/my_prog/d_interface.go
/src/my_prog/d_struct_that_implements_the_interface.go
In main.go
I have package main
, in d_interface.go
and d_struct_that_implements_the_interface.go
I have package my_prog
.
When I try to go build my_prog
I get the following error:
can't load package: package my_prog: found packages my_prog (d_interface.go) and main (main.go) in C:\dev\Code\Go\src\my_prog
Does this mean that any file that belongs to package main
should go in its own folder? If so, what is the reason for this?
This question is related to
go
Make sure that your package is installed in your $GOPATH
directory or already inside your workspace/package.
For example: if your $GOPATH = "c:\go"
, make sure that the package inside C:\Go\src\pkgName
Also, if all you are trying to do is break up the main.go file into multiple files, then just name the other files "package main" as long as you only define the main function in one of those files, you are good to go.
Source: Stackoverflow.com