Skip to content

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

FeatureCommand / FlagWhat it generates
Redis Cache--cache on feature, repository, diCached<Entity>Repository decorator + Redis client factory
CI Pipelinegoca ciGitHub Actions workflows (test, build, deploy)
Middlewaregoca 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

bash
# 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" --cache

What Gets Generated

internal/repository/cached_product_repository.go — A decorator that implements the same ProductRepository interface:

go
type CachedProductRepository struct {
    inner    ProductRepository
    cache    *redis.Client
    cacheTTL time.Duration
    ctx      context.Context
}

func NewCachedProductRepository(
    inner ProductRepository,
    cache *redis.Client,
    ttl time.Duration,
) *CachedProductRepository

Caching strategy:

  • FindByID and FindAll — Check Redis first, delegate on miss, cache the result
  • Save, 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:

go
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:

go
// 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

bash
# 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.25

Flags

FlagDefaultDescription
--providergithub-actionsCI provider
--with-dockerfalseInclude Docker build step
--with-deployfalseInclude deployment workflow
--go-versionauto-detectGo version for CI
--dry-runfalsePreview without writing
--forcefalseOverwrite 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

bash
# 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

TypeDescriptionDependencies
corsCORS headers with configurable origins, methods, headers
loggingStructured request logging with duration and status capture
authJWT token validation with claims extraction into contextgolang-jwt/jwt/v5
rate-limitToken bucket per-IP rate limitinggolang.org/x/time
recoveryPanic recovery → 500 JSON response with optional stack trace
request-idInject X-Request-ID header (UUID) into context and responsegoogle/uuid
timeoutPer-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.go

Auto-Detection in Handlers

When a middleware package exists at internal/middleware/middleware.go, goca handler and goca feature automatically:

  • Import internal/middleware in the generated routes file
  • Use middleware.CORS(...) and middleware.Logging() instead of inline functions

Feature Integration

Use --middleware-types on goca feature to generate middleware alongside a feature:

bash
goca feature Product --fields "name:string" --middleware-types "cors,logging,auth"

Test Coverage

ComponentNew TestsTotal
Cache decorator88
Cache helpers + DI cache88
CI pipeline1515
Middleware2020
Total new51

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 tests

Modified Files

  • cmd/feature.go--cache, --middleware-types flags; generateCompleteFeature signature updated
  • cmd/repository.go — Cache decorator wiring when --cache is set
  • cmd/handler.go — Auto-detect middleware package for handler routes
  • cmd/di.go--cache flag; Redis client field, imports, and decorator wiring
  • cmd/integrate.go — Cache parameter threading
  • cmd/root.go — Register ciCmd and middlewareCmd
  • cmd/mcp_tools_util.go — Register CI and middleware MCP tools
  • docs/commands/index.md — Added ci and middleware entries
  • docs/commands/repository.md — Added --cache documentation
  • docs/commands/feature.md — Added --cache and --middleware-types docs
  • docs/commands/di.md — Added --cache documentation

Upgrade Guide

Install

bash
go install github.com/sazardev/goca@v1.19.0

Use the New Features

bash
# 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:6379

No breaking changes from v1.18.x. All existing commands and flags continue to work unchanged.


See Also

Released under the MIT License.