advanced-lokstra-middleware

Implements YAML-configurable middleware for request and response processing in Lokstra.

8|1|Updated Jun 21, 2025
One-click install
npx skills add https://github.com/primadi/lokstra --skill advanced-lokstra-middleware
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: advanced-lokstra-middleware
Source: https://github.com/primadi/lokstra/tree/main/.github/skills/advanced-lokstra-middleware
Command: npx skills add https://github.com/primadi/lokstra --skill advanced-lokstra-middleware

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Create custom middleware to filter requests and responses, centralize logging, authentication, authorization, and other cross-cutting concerns after the framework is initialized.

Core Features & Use Cases

  • Standard middleware pattern with a Config struct, DefaultConfig, Middleware, MiddlewareFactory, and Register functions, enabling reusable, testable cross-cutting logic.
  • YAML-configurable middlewares that can be composed globally or per-route, including built-in examples like recovery, logging, CORS, rate-limiting, and request-id patterns.
  • Safe integration with lokstra_registry and a request.Context, allowing post-processing hooks and pre-processing decisions without mutating core flow.

Quick Start

  1. Create a new middleware package under middleware/your_middleware with Config, DefaultConfig, Middleware, MiddlewareFactory, and Register.
  2. In your application's bootstrap, call the Register function and invoke your middleware via router.Use(...) or per-route decorators.
  3. Configure via YAML under configs/middlewares.yaml to enable/adjust behavior across the app.

Frequently Asked Questions about advanced-lokstra-middleware

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add authentication and logging middleware to a Go web framework?

You can implement authentication and logging middleware by creating a package with Config, DefaultConfig, Middleware, and Register functions, then applying it globally via router.Use or as per-route decorators during framework bootstrap.

What is the standard pattern for building reusable middleware in Go?

The standard pattern for reusable middleware in Go involves defining a Config struct, DefaultConfig, Middleware, MiddlewareFactory, and Register functions to encapsulate cross-cutting logic like rate limiting and CORS for safe integration.

Can I configure middleware behavior externally using YAML?

Yes, middleware behavior can be configured externally using YAML. By placing settings under configs/middlewares.yaml, developers can enable or adjust cross-cutting concerns like recovery and request-id patterns across the application.

How do I compose per-route middleware for request and response processing?

Per-route middleware for request and response processing is composed by invoking registered middleware via route decorators, allowing pre-processing decisions and post-processing hooks without mutating the core application flow.

Does this middleware approach support cross-cutting modifications without mutating core flow?

Yes, this middleware approach supports cross-cutting modifications safely. It integrates with a lokstra_registry and request.Context to apply pre-processing decisions and post-processing hooks without mutating the core routing flow.