v1.19.0 — Cache, CI & Middleware
Release Date: March 26, 2026
Version 1.19.0 is a feature release that adds three major capabilities: Redis caching with a decorator pattern, CI pipeline generation for GitHub Actions, and standalone middleware generation with 7 composable HTTP middleware types.
Highlights
| Feature | Command / Flag | What it generates |
|---|---|---|
| Redis Cache | --cache on feature, repository, di | Cached<Entity>Repository decorator + Redis client factory |
| CI Pipeline | goca ci | GitHub Actions workflows (test, build, deploy) |
| Middleware | goca middleware <name> | internal/middleware/ package with 7 types |
Redis Cache Layer (--cache flag)
A new --cache / -c flag is available on three commands: goca feature, goca repository, and goca di. It generates a decorator pattern that wraps your database repository with Redis caching — zero changes required to existing code.
Usage
# Generate a feature with Redis caching
goca feature Product --fields "name:string,price:float64" --cache
# Add cache to an existing repository
goca repository Product --database postgres --cache
# Wire cache decorators in the DI container
goca di --features "Product,User" --cacheWhat Gets Generated
internal/repository/cached_product_repository.go — A decorator that implements the same ProductRepository interface:
type CachedProductRepository struct {
inner ProductRepository
cache *redis.Client
cacheTTL time.Duration
ctx context.Context
}
func NewCachedProductRepository(
inner ProductRepository,
cache *redis.Client,
ttl time.Duration,
) *CachedProductRepositoryCaching strategy:
FindByIDandFindAll— Check Redis first, delegate on miss, cache the resultSave,Update,Delete— Delegate to inner repository, then invalidate cache- Search methods (e.g.
FindByEmail) — Delegate directly (no caching)
internal/cache/redis.go — Redis client factory:
func NewRedisClient() (*redis.Client, error)Reads REDIS_URL, REDIS_PASSWORD, REDIS_DB from environment variables with sensible defaults (localhost:6379, no password, DB 0).
DI Container Integration
When --cache is passed to goca di or during feature auto-integration:
// Constructor now accepts redis client
func NewContainer(db *gorm.DB, redisClient *redis.Client) *Container
// setupRepositories wraps each repo with the cache decorator
func (c *Container) setupRepositories() {
baseProductRepo := repository.NewPostgresProductRepository(c.db)
c.productRepo = repository.NewCachedProductRepository(
baseProductRepo, c.redisClient, 5*time.Minute,
)
}Redis Dependency
Uses github.com/redis/go-redis/v9 — the official Go Redis client.
CI Pipeline Generation (goca ci)
A new standalone command that generates CI/CD pipeline configuration files.
Usage
# Basic — generates test + build workflows
goca ci
# With Docker build
goca ci --with-docker
# With deployment workflow
goca ci --with-deploy
# Specify Go version (auto-detected from go.mod by default)
goca ci --go-version 1.25Flags
| Flag | Default | Description |
|---|---|---|
--provider | github-actions | CI provider |
--with-docker | false | Include Docker build step |
--with-deploy | false | Include deployment workflow |
--go-version | auto-detect | Go version for CI |
--dry-run | false | Preview without writing |
--force | false | Overwrite existing files |
Generated Files
.github/workflows/
├── test.yml — Runs go test, go vet, golangci-lint
├── build.yml — Builds binary + optional Docker image
└── deploy.yml — Deploy workflow (when --with-deploy)Smart defaults:
- Go version auto-detected from
go.mod - Database service containers (PostgreSQL, MySQL) detected from
.goca.yaml - Standard CI steps: checkout, setup-go, cache modules, test, vet
Middleware Generation (goca middleware)
A new standalone command that generates a composable middleware package for HTTP handlers.
Usage
# Generate with default types (cors, logging, recovery)
goca middleware myapp
# Specify middleware types
goca middleware myapp --types "cors,logging,auth,rate-limit,recovery,request-id,timeout"7 Middleware Types
| Type | Description | Dependencies |
|---|---|---|
cors | CORS headers with configurable origins, methods, headers | — |
logging | Structured request logging with duration and status capture | — |
auth | JWT token validation with claims extraction into context | golang-jwt/jwt/v5 |
rate-limit | Token bucket per-IP rate limiting | golang.org/x/time |
recovery | Panic recovery → 500 JSON response with optional stack trace | — |
request-id | Inject X-Request-ID header (UUID) into context and response | google/uuid |
timeout | Per-request context deadline | — |
Generated Structure
internal/middleware/
├── middleware.go — Chain() helper for composing middleware
├── cors.go
├── logging.go
├── auth.go
├── rate_limit.go
├── recovery.go
├── request_id.go
└── timeout.goAuto-Detection in Handlers
When a middleware package exists at internal/middleware/middleware.go, goca handler and goca feature automatically:
- Import
internal/middlewarein the generated routes file - Use
middleware.CORS(...)andmiddleware.Logging()instead of inline functions
Feature Integration
Use --middleware-types on goca feature to generate middleware alongside a feature:
goca feature Product --fields "name:string" --middleware-types "cors,logging,auth"Test Coverage
| Component | New Tests | Total |
|---|---|---|
| Cache decorator | 8 | 8 |
| Cache helpers + DI cache | 8 | 8 |
| CI pipeline | 15 | 15 |
| Middleware | 20 | 20 |
| Total new | 51 |
All 51 new tests pass. Full test suite verified clean.
New Files
cmd/
├── cache_decorator.go — Redis cache decorator generator
├── cache_helpers.go — Redis client package generator
├── cache_decorator_test.go — 8 tests
├── cache_helpers_test.go — 8 tests
├── ci.go — goca ci command
├── ci_templates.go — CI workflow templates
├── ci_helpers.go — CI helper functions
├── ci_test.go — 15 tests
├── middleware.go — goca middleware command
├── middleware_templates.go — Middleware code templates
├── middleware_helpers.go — Middleware package generator
└── middleware_test.go — 20 testsModified Files
cmd/feature.go—--cache,--middleware-typesflags;generateCompleteFeaturesignature updatedcmd/repository.go— Cache decorator wiring when--cacheis setcmd/handler.go— Auto-detect middleware package for handler routescmd/di.go—--cacheflag; Redis client field, imports, and decorator wiringcmd/integrate.go— Cache parameter threadingcmd/root.go— RegisterciCmdandmiddlewareCmdcmd/mcp_tools_util.go— Register CI and middleware MCP toolsdocs/commands/index.md— Added ci and middleware entriesdocs/commands/repository.md— Added--cachedocumentationdocs/commands/feature.md— Added--cacheand--middleware-typesdocsdocs/commands/di.md— Added--cachedocumentation
Upgrade Guide
Install
go install github.com/sazardev/goca@v1.19.0Use the New Features
# Full feature with caching + middleware
goca feature Product \
--fields "name:string,price:float64" \
--cache \
--middleware-types "cors,logging,auth"
# Generate CI pipelines
goca ci --with-docker
# Set Redis env vars for cache
export REDIS_URL=localhost:6379No breaking changes from v1.18.x. All existing commands and flags continue to work unchanged.
See Also
- goca ci — CI command reference
- goca middleware — Middleware command reference
- goca repository --cache — Cache decorator reference
- goca feature --cache — Feature with cache
- goca di --cache — DI container with cache wiring