Skip to content

Latest commit

 

History

History
50 lines (40 loc) · 2.52 KB

README.md

File metadata and controls

50 lines (40 loc) · 2.52 KB

The /apps directory stores source code of project application(s) using the Go main package that can be compiled to the binary executable. It is often named /cmd instead, but because the name is not so appropriate and could lead to false assumptions it has been renamed for this template repository to better describe the actual content.

Directory Structure

A common practice is that each application is placed in an individual directory that should match the name of the resulting binary executable. The structure always depends on the type and use case(s) of the application, but in general the code only consists of the main package and function that mainly imports and invokes reuseable code from the /internal and /pkg directories.

Code that is only relevant for an individual application like configurations, internal logic and commands can also be placed inside directories like config, internal and internal/cmd. In comparison, code that is reusable and could be imported from outside the module should never be placed in the application specific directory but /pkg. Please see the example below for a common and practical usage pattern.

Example

Given the API defined in the example of the /api directory and additionally assuming another service application named notes-sync the structure for the application could be created as follows:

apps
├─ notes
│  ├─ config
│  └─ internal
│     └─ cmd
│        ├─ archive
│        ├─ create
│        └─ delete
└─ notes-sync
    ├─ config
    └─ internal
        └─ cmd
           ├─ export
           └─ serve

References

Next to the experience with own projects and golang-standards/project-layout, many other large, production-grade and well-known projects of the Go ecosystem have been used as references: