0

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
1
  • 2
    You can't import a main package. You need to refactor the code. Commented Sep 15, 2016 at 12:25

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.