middleware-skill

Generate and register HTTP middleware templates for go-zero API services.

Updated Jan 24, 2026
One-click install
npx skills add https://github.com/Penitence1992/go-zero-backend-skills --skill middleware-skill
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: middleware-skill
Source: https://github.com/Penitence1992/go-zero-backend-skills/tree/main/skills/middleware-skill
Command: npx skills add https://github.com/Penitence1992/go-zero-backend-skills --skill middleware-skill

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides a standardized approach to building and wiring HTTP middleware for go-zero services, including reusable templates and clear integration steps.

Core Features & Use Cases

  • Template-based middleware: Create reusable middleware templates that can be instantiated for different routes or services.
  • Registration guidance: Instructions to attach middleware to specific routes via .api files or globally via the ServiceContext.
  • Real-world example: Implement a logging or authentication middleware and wire it into an existing API with minimal boilerplate.

Quick Start

Create a new middleware using the provided template under internal/middleware/. Then register it in the API definition or in main.go as part of the server setup, and wire it in service_context.go if needed.

Frequently Asked Questions about middleware-skill

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

FAQPage Schema
How do I create and register HTTP middleware in a go-zero project?

To create and register HTTP middleware in a go-zero project, use a template to generate the middleware under internal/middleware/, then wire it into the ServiceContext or attach it to specific routes via the .api definition file.

What is the best way to attach route-specific middleware using go-zero?

The best way to attach route-specific middleware in go-zero is by defining the middleware directly within your .api file configuration, ensuring the generated code applies the middleware only to designated routes.

Can I apply global middleware across all routes in a go-zero API service?

Yes, you can apply global middleware across all routes in a go-zero API service by wiring the middleware component directly into the ServiceContext setup during server initialization in main.go.

Does go-zero support template-based code generation for middleware?

Yes, go-zero supports template-based code generation for middleware. This approach enforces consistent middleware patterns and reduces boilerplate when instantiating reusable components like logging or authentication layers.

How do I wire a custom authentication middleware into a go-zero ServiceContext?

To wire a custom authentication middleware into a go-zero ServiceContext, instantiate the middleware component and register it within the service_context.go file, making it available for dependency injection across your API routes.