Reputation: 2388
Hi I want to call a method inside the main package, my project struct is like this: src:
Postgres folder:
now I want to call a method inside main package from the go files inside the postgres folder that is from postgres package. I tried to import "foo/src" then using src.Myfunction but I got an error:
import "foo/src" is a program, not an importable package
Upvotes: 0
Views: 964
Reputation: 16534
The package main
is supposed to be used only to implement the binary/command specific code. It usually imports code from other packages to glue everything together. If you need to import something from the package main
, that code is probably not specific to that command, so it should belong to another package. After you refactor the code, you can import it from the package main
and from your other package which also requires it.
Upvotes: 3