如何在GO中另一个包中的文件中使用主包中的函数?

Hi I want to call a method inside the main package, my project struct is like this: src:

  • go files : package main
  • Postgres folder:

    • go files: postgres package

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

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.