A Go starter kit with authentication, authorization, and essential features for building robust web applications.
-
🔐 Authentication & Authorization
- JWT Authentication with refresh token
- Role-based access control (RBAC)
- Permission management
- User management with OTP support
- Token session management
-
🌐 Internationalization
- Multi-language support using go-playground/universal-translator
- Easy language switching
- Translation management
-
📧 Email Service
- Email templates
- SMTP configuration using gomail
- Email queue system
-
⚙️ Configuration
- Environment variables management using godotenv
- Auto-loading .env files
- Configuration validation
-
🗄️ Database
- PostgreSQL with GORM integration
- Database migrations
- Seeding support
-
🛠️ Development Tools
- Hot reload using Air
- API documentation
- Logging system
- Error handling
- Gin - Web framework
- GORM - ORM library
- JWT-Go - JWT implementation
- GoDotEnv - Environment variables
- Universal Translator - Internationalization
- Gomail - Email sending
- Air - Live reload
- Go 1.21 or higher
- PostgreSQL
- Clone the repository & setup package name:
git clone https://github.com/totop275/go-starterkit.git
cd go-starterkit
rm -rf .git
find . -type f -name "*.go" -print0 | xargs -0 sed -i 's#totop275/go-starterkit#{your-name}/{project-name}#g'
sed -i 's#totop275/go-starterkit#{your-name}/{project-name}#g' go.mod
git init- Install dependencies:
go mod download- Copy the example environment file:
cp .env.example .env- Update the
.envfile with your configuration:
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=password
DB_NAME=go_starterkit
JWT_SECRET=lO4m6p/zK1Q9Xy0/M3n8o7J6j5H4g3F2e1D0c9B8a7== #The JWT secret key must be a 256-bit (32-byte) Base64-encoded random string.use this command to generate JWT_SECRET openssl rand -base64 32
- Run the application:
go run main.goOr using Air for hot reload:
airTo seed demo users and credentials for testing:
# Seed the demo data
go run ./seeds/main.goThis will create the following demo users:
- Admin User:
- Email: admin@demo.com
- Password: demo123
- Role: Admin
You can use these credentials to test different user roles and permissions in the application.
The API documentation is available on Postman:
You can import the Postman collection to test the API endpoints directly.
.
├── app/ # Application code
│ ├── handler/ # HTTP handlers
│ ├── middleware/ # HTTP middleware
│ └── models/ # Database models
├── config/ # Configuration files
├── resources/ # Static resources
├── routes/ # Route definitions
├── seeds/ # Database seeds
├── utils/ # Utility functions
├── .air.toml # Air configuration
├── .env # Environment variables
├── .env.example # Example environment variables
├── go.mod # Go module file
├── go.sum # Go module checksum
└── main.go # Main application file
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m '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.
- Gin Web Framework
- GORM
- Air
- All other open-source projects that made this starter kit possible