Package structure

Normally my projects are fairly small, usually less than 5 packages, so it is really not a problem for me. I just dump them in a folder named pkg. I usually use this structure:

cmd
pkg
 - pkg1
 - pkg2
 - ...

My question is if there is a purpose in Go for creating subfolders in the pkg folder, other that just grouping things together, that are related somehow?

Example:

cmd
pkg
 - folder1
   - pkg1
   - pkg2
 - folder2
   - pkg3
   - pkg4
   - pkg5

And what happens if for example folder1 is not empty (ie contains a *.go file), would that create a “special” relationship between the package folder1 and pkg1 and pkg2 in any way?

cmd
pkg
 - folder1
   - main.go
   - pkg1
     - main.go
   - pkg2
     - main.go
  - ...

Or would they have no special relation at all (other than, that you decided yourself to group them together)?

I do it this way.

- src
   - project 1
      - main 
         - package main
         - package main 
      - other
         - package other
         - package other
         - package other
   - project 2
      - main 
         - package main
         - package main 
      - other
         - package other
         - package other
         - package other

I break up packages to be easier to maintain. But it is the name of the folder and the package name that matters. Not the file name itself.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.