# README
Golang with Echo and Mongo Template
This is a template for a Golang project using the Echo framework and MongoDB. It includes a basic project structure, configuration, and Docker setup.
Table of Contents
Overview
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
Installation
- 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
Usage
- 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
Configuration
- 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, ...
Testing
- Run tests:
make test
- Run tests with coverage:
make coverage
Deployment
- With existing Dockerfile, you can deploy the application to any cloud provider
- Update the Dockerfile if needed
Contributing
- Fork the repository
- Create a new branch
- Make your changes
- Create a pull request