This is the directory structure for my Go project:
my_project
|
main.go
- my_package
|
- my_package.go
On main.go this works ok:
import ( "my_package/my_package" )
But when I create a new folder "examples" to test some new functionalities of the package, tha main.go cannot import the package as expected:
my_project
|
main.go
- my_package
|
- my_package.go
- examples
|
- main.go
importing package from parent directory:
import ( "../my_package/my_package" )
Trying running examples/main.go does not work:
cd examples
go run main.go
build _/mypath/my_project/my_package: cannot find module for path _/mypath/my_project/my_package
Shouldn't I import local packages from parent directories?
Is it always compulsory to have the package modules on subfolders of main.go?
Is there any simple and clear way to organize main/test/debug go programs w/ shared dependencies on local packages?
I've read on golang modules and local packages that maybe I should use abosulte paths for importing packages, but I don't like that option because this is a code meant to be uloaded to a repository, so absolute paths wouldn't work on other implementations.