Esta página se muestra en inglés. Una traducción al español está en curso.
ScriptsJul 1, 2026·3 min de lectura

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.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
Martini Web Framework
Comando de instalación directa
npx -y tokrepo@latest install cecc8c39-7568-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con 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

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados