Documentation ¶
Overview ¶
Martini is a powerful package for quickly writing modular web applications/services in Golang.
For a full guide visit http://github.com/codegangsta/martini
package main import "github.com/codegangsta/martini" func main() { m := martini.Classic() m.Get("/", func() string { return "Hello world!" }) m.Run() }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClassicMartini ¶
ClassicMartini represents a Martini with some reasonable defaults. Embeds the router functions for convenience.
func Classic ¶
func Classic() *ClassicMartini
Classic creates a classic Martini with some basic default middleware - martini.Logger, martini.Recovery, and martini.Static.
type Context ¶
type Context interface { inject.Injector // Next is an optional function that Middleware Handlers can call to yield the until after // the other Handlers have been executed. This works really well for any operations that must // happen after an http request Next() // contains filtered or unexported methods }
Context represents a request context. Services can be mapped on the request level from this interface.
type Handler ¶
type Handler interface{}
Handler can be any callable function. Martini attempts to inject services into the handler's argument list. Martini will panic if an argument could not be fullfilled via dependency injection.
func Logger ¶
func Logger() Handler
Logger returns a middleware handler that logs the request as it goes in and the response as it goes out.
type Martini ¶
Martini represents the top level web application. inject.Injector methods can be invoked to map services on a global level.
func New ¶
func New() *Martini
New creates a bare bones Martini instance. Use this method if you want to have full control over the middleware that is used.
func (*Martini) Action ¶
Action sets the handler that will be called after all the middleware has been invoked. This is set to martini.Router in a martini.Classic().
func (*Martini) Run ¶
func (m *Martini) Run()
Run the http server. Listening on os.GetEnv("PORT") or 3000 by default.
type Params ¶
Params is a map of name/value pairs for named routes. An instance of martini.Params is available to be injected into any route handler.
type Router ¶
type Router interface { // Get adds a route for a HTTP GET request to the specified matching pattern. Get(string, ...Handler) // Post adds a route for a HTTP POST request to the specified matching pattern. Post(string, ...Handler) // Put adds a route for a HTTP PUT request to the specified matching pattern. Put(string, ...Handler) // Delete adds a route for a HTTP DELETE request to the specified matching pattern. Delete(string, ...Handler) // Handle is the entry point for routing. This is used as a martini.Handler Handle(http.ResponseWriter, *http.Request, Context) }
Router is Martini's de-facto routing interface. Supports HTTP verbs, stacked handlers, and dependency injection.