This is a template for a Golang project using the Echo framework and MongoDB. It includes a basic project structure, configuration, and Docker setup.
Structure of the project:
┣📦 .github # Github actions
┃
┣📦 cmd # Command line
┃ ┗ 📂 api
┃ ┗ 📂 server # Setup routes, middlewares, services,...
┃ ┣ 📂 test # Integration tests
┃ ┗ 📜 main.go # Api entry point
┣ 📦 config # Configuration
┃ ┣ 📜 env.go # Environment setup
┃ ┗ 📜 logger.go # Logger setup: zerolog, openobserve, stdout
┣ 📦 constants # Constants: errors, mail, ...
┣ 📦 docs # Documents
┣ 📦 internal # Internal packages
┃ ┣ 📂 health # Health module
┃ ┃ ┣ 📜 health.go # Health check handler
┃ ┃ ┗ 📜 route.go # Health check route
┃ ┣ 📂 user
┃ ┃ ┣ 📂 services
┃ ┃ ┃ ┣ 📜 user.go # User service
┃ ┃ ┃ ┗ 📜 user_test.go # User service test
┃ ┃ ┗ 📂 handler
┃ ┃ ┣ 📜 user.go # User handler
┃ ┃ ┗ 📜 user_test.go # User handler test
┃ ┗ 📂 middlleware # Middlewares
┣ 📦 pkg # Public packages
┃ ┣ 📂 db
┃ ┃ ┣ 📂 models # Database models
┃ ┃ ┗ 📜 init.go # Database connection
┃ ┣ 📂 openobserve # Openobserve
┃ ┗ 📂 utils # Utilities
┃
┣ 📜 .air.toml # Air configuration
┣ 📜 .env.example # Env example
┣ 📜 .gitignore # Git ignore
┣ 📜 app.compose.yml # App docker compose
┣ 📜 compose.yml # Docker compose
┣ 📜 Dockerfile # Dockerfile
┣ 📜 go.mod # Go modules
┣ 📜 go.sum # Go modules
┣ 📜 Makefile # Makefile
┗ 📜 README.md # Readme
- Clone the repository
- Install dependencies
go mod tidy
- Install Air for hot reload:
go install github.com/cosmtrek/air@latest
- Set up configuration (if any)
- Copy
.env.example
to.env
and update the values
- Run bootstrapping:
make compose
to start the services- This will start the Openobserve service that runs on port 5080
- You can access the Openobserve dashboard at
http://localhost:5080
- Login with the default email and password in
compose.yml
, or update the values - Access the Ingestion API - Trace
- Copy the
Authorization
header value and update theOPENOBSERVE_CREDENTIAL
in the.env
file - Access the Trace Tab to view the traces
- You can access the Openobserve dashboard at
- This will start the MongoDB service that runs on port 27017
- Access the MongoDB connection string and update the
MONGO_URI
in the.env
file
- Access the MongoDB connection string and update the
- This will start the Openobserve service that runs on port 5080
- Run the application:
make run
- Run the application with hot reload:
make watch
- Run application with Docker:
make start
- Stop the docker container:
make stop
- Shutdown and clean up:
make shutdown
- Restart the application:
make restart
- Update the configuration in the
.env
file - Update the logger configuration in
config/logger.go
- Update the environment setup in
config/env.go
- Update the database connection in
pkg/db/init.go
- Update the database models in
pkg/db/models
- Add new routes in
cmd/api/server/routes.go
- Add new services in
internal/<module>/services
- Add new handlers in
internal/<module>/handlers
- Add new middlewares in
internal/middleware
- Add new constants in
constants
- If you want to add new packages, add them in
pkg
such aspkg/<package>
: jwt, cookie, mail, cache, oauth, s3, ...
- Run tests:
make test
- Run tests with coverage:
make coverage
- With existing Dockerfile, you can deploy the application to any cloud provider
- Update the Dockerfile if needed
- Fork the repository
- Create a new branch
- Make your changes
- Create a pull request