Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsJul 1, 2026·3 min de lecture

Martini — Classy Composable Web Framework for Go

Martini is a Go web framework that uses reflection-based dependency injection and a modular middleware stack to provide an expressive, Sinatra-like API for building web applications and services.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Martini Web Framework
Commande d'installation directe
npx -y tokrepo@latest install cecc8c39-7568-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

Martini is a Go web framework that provides an expressive, Sinatra-like API for handling HTTP requests. It relies on reflection-based dependency injection to wire services into handlers automatically, letting developers write concise route handlers without manual plumbing.

What Martini Does

  • Maps HTTP routes to handler functions with automatic parameter injection
  • Provides a composable middleware stack for request processing pipelines
  • Includes a Classic() preset with logging, recovery, and static file serving
  • Supports route groups for organizing related endpoints under shared prefixes
  • Injects services into handlers automatically via a reflection-based injector

Architecture Overview

Martini's core is an injector that resolves function parameters at runtime using Go's reflect package. When a request arrives, the router matches it to a handler, the middleware stack runs in sequence, and the injector supplies dependencies (request, response writer, custom services) to each handler. This design keeps handlers short but incurs a small reflection overhead per request.

Self-Hosting & Configuration

  • Requires Go 1.18 or later
  • Install with go get github.com/go-martini/martini
  • martini.Classic() bundles Logger, Recovery, and Static middleware
  • Bind custom services with m.Map() or m.MapTo() for interface injection
  • Set the MARTINI_ENV environment variable to production to disable debug output

Key Features

  • Sinatra-inspired routing with clean, expressive handler signatures
  • Dependency injection removes boilerplate wiring of services
  • Middleware is composable — add, remove, or reorder with a single call
  • Route groups share middleware and path prefixes
  • Minimal core with optional add-on packages for sessions, rendering, and auth

Comparison with Similar Tools

  • Gin — uses httprouter for speed and avoids reflection; Martini trades performance for expressiveness
  • Echo — similar middleware model but without reflection-based DI
  • Negroni — middleware-only library by the same author; Martini adds routing and DI on top
  • Revel — full MVC framework; Martini is a lighter, library-style approach
  • Fiber — fasthttp-based for throughput; Martini targets developer ergonomics

FAQ

Q: Is Martini still maintained? A: The repository is not archived but receives infrequent updates. It remains usable and stable for existing projects.

Q: Does reflection hurt performance? A: There is a measurable overhead per request compared to non-reflective routers like httprouter, but for most workloads it is not the bottleneck.

Q: Can I use Martini with Go modules? A: Yes. The github.com/go-martini/martini import path works with Go modules.

Q: What is the relationship between Martini and Negroni? A: Both were created by the same developer. Negroni focuses solely on middleware composition, while Martini adds routing and dependency injection.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires