Scripts2026年7月1日·1 分钟阅读

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.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Martini Web Framework
直接安装命令
npx -y tokrepo@latest install cecc8c39-7568-11f1-9bc6-00163e2b0d79 --target codex

先 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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产