Golang Subdirectories

Is there a way to create a subdirectory for some of my files? This is clean for organizing files. I have a large number of small structures / methods that I would like to put in my own files and in a subdirectory, but I do not want to put them in my own package. They rely on other features of my project. Each of them is anywhere from 10-50 lines, and I stuck them in one file, but this is ugly.

+8
go
source share
2 answers

There is no way to do this. Go does this on purpose, because if you think you need a different subdirectory. Most likely you will need another package. In addition, if you really do not need a subpackage, you can simply split all these small structures and their corresponding methods into separate files in a single package.

+9
source share

you can also put them in a separate package and they import everything from the parent package:

package mainpackage import . "mysubpackage" // with all the little sub directory 
0
source share

All Articles