A production-ready Go project scaffold that provides a solid foundation for building scalable web applications using modern Go practices and popular libraries.
- 🚀 Modern project structure following Go best practices
- 🔒 JWT-based authentication
- 📝 Structured logging with rotation (Zap + Lumberjack)
- 🗄️ Database integration with GORM
- 🔄 Redis caching support
- ⚡ Dependency injection using Wire
- 🔧 YAML-based configuration
- 🧪 Testing setup with mocks
- 🛡️ Middleware support
- 🎯 Clean architecture pattern
.
├── cmd/
│ └── api/ # Application entrypoints
├── config/ # Configuration files
├── internal/ # Private application code
│ ├── api/ # HTTP handlers
│ ├── middleware/ # HTTP middleware
│ ├── model/ # Domain models
│ ├── repository/ # Data access layer
│ ├── router/ # HTTP router setup
│ ├── service/ # Business logic
│ └── wire/ # Dependency injection
├── pkg/ # Public libraries
│ ├── cache/ # Caching utilities
│ ├── database/ # Database utilities
│ └── logger/ # Logging utilities
└── scripts/ # Build/deployment
- Web Framework: Gin
- ORM: GORM
- Configuration: Viper
- Logging: Zap
- Caching: go-redis
- Authentication: JWT using golang-jwt
- Dependency Injection: Wire
- Go 1.23 or higher
- MySQL
- Redis
- Clone the repository:
git clone https://github.com/yourusername/go-project-starter.git
cd go-project-starter- Install dependencies:
go mod download- Copy the example configuration:
cp config/config.example.yaml config/config.yaml- Update the configuration in
config/config.yamlwith your settings.
- Start the development server:
make run
# or
go run cmd/api/main.go- Run tests:
make test
# or
go test ./...The application uses YAML-based configuration. Key configuration options include:
server:
port: 8080
mode: development # or production
database:
driver: mysql
host: localhost
port: 3306
name: myapp
user: root
password: secret
redis:
host: localhost
port: 6379
db: 0
jwt:
secret: your-secret-key
expiration: 24h
logging:
level: info
filename: app.log
maxSize: 100
maxBackups: 3
maxAge: 28cmd/: Contains the main applications of the projectinternal/: Contains the private application and library codeapi/: HTTP handlers and route definitionsmiddleware/: HTTP middleware componentsmodel/: Domain models and business logic interfacesrepository/: Data access layer implementationsservice/: Business logic implementations
pkg/: Libraries that can be used by external applicationsconfig/: Configuration files and templates
- Define your domain models in
internal/model/ - Implement the repository interface in
internal/repository/ - Add business logic in
internal/service/ - Create HTTP handlers in
internal/api/ - Register routes in
internal/router/
The project includes examples for:
- Unit tests
- Integration tests
- Mock implementations
Run tests with coverage:
make test-coverage- 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.