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 ¶
const ( Dev string = "development" Prod string = "production" Test string = "test" )
Variables ¶
var Env string = Dev
Env is the environment that Martini is executing in. The MARTINI_ENV is read on initialization to set this variable.
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) Handlers ¶
Handlers sets the entire middleware stack with the given Handlers. This will clear any current middleware handlers. Will panic if any of the handlers is not a callable function
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 ResponseWriter ¶
type ResponseWriter interface { http.ResponseWriter // Status returns the status code of the response or 0 if the response has not been written. Status() int // Written returns whether or not the ResponseWriter has been written. Written() bool // Size returns the size of the response body. Size() int }
ResponseWriter is a wrapper around http.ResponseWriter that provides extra information about the response. It is recommended that middleware handlers use this construct to wrap a responsewriter if the functionality calls for it.
func NewResponseWriter ¶
func NewResponseWriter(rw http.ResponseWriter) ResponseWriter
NewResponseWriter creates a ResponseWriter that wraps an http.ResponseWriter
type Route ¶
type Route interface { // URLWith returns a rendering of the Route's url with the given string params. URLWith([]string) string }
Route is an interface representing a Route in Martini's routing layer.
type Router ¶
type Router interface { // Get adds a route for a HTTP GET request to the specified matching pattern. Get(string, ...Handler) Route // Patch adds a route for a HTTP PATCH request to the specified matching pattern. Patch(string, ...Handler) Route // Post adds a route for a HTTP POST request to the specified matching pattern. Post(string, ...Handler) Route // Put adds a route for a HTTP PUT request to the specified matching pattern. Put(string, ...Handler) Route // Delete adds a route for a HTTP DELETE request to the specified matching pattern. Delete(string, ...Handler) Route // NotFound sets the handler that is called when a no route matches a request. Throws a basic 404 by default. NotFound(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.