Hi everyone, today I want to share a Go project structure that I have used and found useful. This project structure is suitable for medium and small projects, and even large projects. The way folders and files are organized in this project structure is similar to other programming languages such as NodeJS or Java. This helps everyone to have a more comprehensive and easier understanding when learning about Go. I hope it will be useful and here is my Go project structure.
.
├── cmd/ # Contains executable applications
│ ├── cli/ # Command-line application
│ ├── cronjob/ # Scheduled jobs
│ └── server/ # Server application
│ └── main.go # Run the application
├── config/ # Configuration for applications
│ └── config.yaml # Main configuration file
├── docs/ # Project documentation
├── global/ # Global variables
├── internal/ # Internal packages
│ ├── controller/ # Handle client requests
│ ├── initialize/ # Initialize necessary components
│ ├── middlewares/ # Server middlewares
│ ├── models/ # Structs representing data
│ ├── repo/ # Query data from the database
│ ├── routers/ # Define routes for the server
│ ├── service/ # Handle business logic
├── migrations/ # Database migration scripts
├── pkg/ # Reusable packages
│ ├── logger/ # Logging for the application
│ ├── response/ # Handle response to the client
│ ├── setting/ # Application settings
│ └── utils/ # Utility functions
├── scripts/ # Development support scripts
├── tests/ # Test cases for the application
├── third_party/ # Third-party libraries
├── .gitignore # Git ignore file
├── go.mod # Go dependencies management
├── go.sum # Contains checksums of dependencies
├── LICENSE # Project license
└── README.md # Project description
This is the result of my project structure on Visual Studio Code
If you found this article useful and interesting, please share it with your friends and family. I hope you found it helpful. Thanks for reading 🙏
Let's get connected! You can find me on:
- Medium: Quang Hieu (Bee) -- Medium
- Dev: Quang Hieu (Bee) -- Dev
- Linkedin: Quang Hieu (Bee) -- Linkedin
- Buy Me a Coffee: Quang Hieu (Bee) -- buymeacoffee
Top comments (3)
This is a typical, bad-structured project in Go. This is a bad template, which is used only in Go shit stuff, mate. I don't blame you, but I do blame the people who provided that shit, mate.
I guess the pkg folder if for reusable packages written by the author, but third_party doesn't make sense to me for the same reason that you mention.
Other than that I mostly agree with your comment, for me it seems a company policy made by someone that was learning Go at that moment.
where did you bring initialize from?! use infra instead