I am trying to write a go project with several sub projects. For an simple example the project looks like this
Main
|- package one
|- package one.one
|- package one.two
|- package two
From my main package i can use any function or structure of any sub package By importing them. But My question is how can i access an struct or function of main from any sub package.
Thanks. I solved this problem by using an third package. Pretty easy that way.
By importing the "subpackages" in main. But do not produce an import cycle (Restructure your code in this case).
Note that Go has (almost*) no notion of _sub_package: These are all plain packages and the directory layout has no influence on imports and usability/accessability of exported functions, types, methods, fields, variables and constants.
*) Internal packages and vendored packages depend on directory layout.