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