gitmyhub

martini

Go ★ 12k updated 4y ago

Classy web framework for Go

An archived Go web framework with routing, middleware stacking, and automatic dependency injection into handler functions. Still used by legacy projects but receives no security patches.

Gosetup: moderatecomplexity 3/5

Martini is a web framework for Go that makes it quick to build web servers and HTTP APIs. It is no longer maintained, as the README prominently states at the top, so it is mostly of historical interest or still in use by projects that have not yet migrated away.

The framework centers on a routing and middleware system. You define routes by pairing an HTTP method (GET, POST, PUT, DELETE, and so on) with a URL pattern, and attach one or more handler functions to each route. URL patterns can include named parameters, glob wildcards, and regular expressions. Handlers can be stacked so that authentication or authorization checks run before the main logic.

A notable feature is dependency injection into handler functions. Martini inspects the argument types of each handler at runtime and automatically provides matching services, such as the HTTP request object, a logger, or any custom object you have registered. This means you declare what your handler needs as function arguments and Martini supplies them, rather than having to pass everything explicitly through a context object.

The Classic() setup is a quick-start configuration that includes request and response logging, panic recovery (so an unhandled error does not crash the whole server), static file serving, and the router. Additional middleware is available through the separate martini-contrib organization on GitHub.

Because the project is no longer maintained, it does not receive security patches or compatibility updates. Newer Go web frameworks and the Go standard library's own HTTP tooling have largely replaced it.

Where it fits