Hello Team,
I have the below code structure & I’m trying to call a function defined under the same package (main) but in different folder (I’m not sure if this is valid). If its valid, then my understanding is that I should be able to use the function defined in another “folder1” in main.go without explicit import right…?
No, this is not valid. All files that belong to the same package must reside in the same folder, according to the language reference:
A set of files sharing the same PackageName form the implementation of a package. An implementation may require that all source files for a package inhabit the same directory.
as @christophberger said, you basically have 2 packages: dummy/main, and folder_1/main. You are dealing with 2 packages, they just happen to be both called main.
hmm @telo_tade thanks for the response. The folder_1 is under dummy folder (i.e its the subdir), so I was wondering since dummy is the parent folder it should be able to use the functions in folder_1 without explicit import, but I’m unable to.