A robust Go web application starter using the Echo framework. This project provides a solid foundation for building production-ready REST APIs with features like authentication, caching, email sending, and more.
- Framework: Built with Echo web framework
- Database: PostgreSQL with connection pooling
- Caching: Redis integration
- Authentication: JWT-based auth with refresh tokens
- API Documentation: Auto-generated Swagger/OpenAPI docs
- Environment Config: Using godotenv
- External Services:
- SendGrid for email delivery
- OpenAI integration
- Speechmatics API integration
- AWS Integration: Ready-to-use AWS configuration
.
├── cmd/
│ └── main.go # Application entry point with Swagger annotations
├── docs/ # Swagger/OpenAPI documentation
│ ├── docs.go # Generated Swagger spec
│ ├── swagger.json # Generated Swagger JSON
│ └── swagger.yaml # Generated Swagger YAML
├── internal/
│ ├── app/ # Application initialization
│ │ └── application.go # App setup and configuration
│ ├── config/ # Configuration management
│ │ └── config.go # Configuration structs and loading
│ ├── db/ # Database management
│ │ ├── migration/ # SQL migrations
│ │ │ ├── 20241111021715_create_users_table.up.sql
│ │ │ └── 20241111042819_create_posts_table.up.sql
│ │ ├── query/ # SQL queries
│ │ │ ├── posts.sql
│ │ │ └── users.sql
│ │ ├── db.go # Database connection setup
│ │ └── schema.sql # Database schema
│ ├── env/ # Environment variable handling
│ │ └── env.go # Environment utilities
│ ├── handler/ # HTTP handlers
│ │ ├── handler.go # Handler initialization
│ │ ├── health.go # Health check handler
│ │ └── user.go # User-related handlers
│ ├── server/ # HTTP server setup
│ │ ├── routes.go # Route definitions
│ │ ├── server.go # Server configuration
│ │ └── start.go # Server startup logic
│ ├── store/ # Generated database code
│ │ ├── db.go # Database interface
│ │ ├── models.go # Generated models
│ │ ├── posts.sql.go # Generated post queries
│ │ ├── querier.go # Query interface
│ │ └── users.sql.go # Generated user queries
│ └── validator/ # Request validation
│ └── validator.go # Custom validator setup
├── .air.toml # Air configuration for hot reload
├── .env.example # Example environment variables
├── .gitignore # Git ignore rules
├── go.mod # Go module definition
├── go.sum # Go module checksums
├── Makefile # Build and development commands
├── README.md # Project documentation
└── sqlc.yaml # SQLC configuration
- Go 1.21 or higher
- PostgreSQL
- Redis
- Make (for Makefile usage)
- Air (for hot reloading)
- DBMate (for database migrations)
-
Clone the repository
git clone https://github.com/yourusername/echo-starter.git cd echo-starter
-
Copy environment file
cp .env.example .env
-
Modify environment variables
# Application APP_NAME=echo-starter APP_ENV=development APP_PORT=1323 # Database DB_HOST=localhost DB_PORT=5432 DB_NAME=echo_starter_db DB_USER=postgres DB_PASSWORD=postgres # Add other necessary variables...
-
Install dependencies
go mod download make setup-dev
-
Run the application
go run cmd/api/main.go
-
Run DBMate
dbmate up
-
Run the Application
air
Once the application is running, you can access the Swagger documentation at:
http://localhost:3000/swagger/index.html
The application uses environment variables for configuration. See .env.example
for all available options.
This project uses commitlint to validate commit messages.
Commit Messages must be in the following format:
<type>[optional scope]: <subject>
Valid types:
- feat: A new feature
- fix: A bug fix
- docs: Documentation only changes
- style: Changes that do not affect the meaning of the code (white-space, formatting etc)
- refactor: A code change that neither fixes a bug nor adds a feature
- perf: A code change that improves performance
- test: Adding missing tests or correcting existing tests
- build: Changes that affect the build system or external dependencies
- ci: Changes to our CI configuration files and scripts
- chore: Other changes that don't modify src or test files
- revert: Reverts a previous commit
go test ./...
golangci-lint run
go build -o bin/api cmd/api/main.go
docker build -t echo-starter .
docker run -p 3000:3000 echo-starter
- Development:
.env.development
- Staging:
.env.staging
- Production:
.env.production
Configure SendGrid for email delivery:
SENDGRID_API_KEY=your_api_key
SENDGRID_FROM_EMAIL=no-reply@yourapp.com
SENDGRID_FROM_NAME=Your App
Set up OpenAI integration:
OPENAI_API_KEY=your_api_key
OPENAI_MODEL=gpt-4
OPENAI_MAX_TOKENS=2000
Configure Speechmatics API:
SPEECHMATICS_API_KEY=your_api_key
SPEECHMATICS_BASE_URL=https://asr.api.speechmatics.com/v2
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'feat: Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Echo Framework
- godotenv
- All other open-source packages used in this project
For support, email your-email@example.com or open an issue in the GitHub repository.