Documentation ¶
Overview ¶
Package martini_sandwich is a martini-adapter for sandwich that provides the martini request parameters to the middleware stack.
The Middleware implementation in this package is identical to the normal sandwich.Middleware except:
- it provides the martini.Params type by default for accessing route parameters
- it has a .H field for getting the martini handler easily.
Here's a simple example of using this:
s := martini_sandwich.TheUsual().Provide(...).With(...) m := martini.Classic() ... m.Get("/user/:id/", s.Provide(userdb).With(getUser).H) // <-- Note the .H ... func getUser(w http.ResponseWriter, p martini.Params, udb UserDb) error { userId := p["id"] user, err := udb.Lookup(userId) if err != nil { return err // or wrap with sandwich.Error{...} } return json.NewEncoder(w).Encode(user) }
Index ¶
- type Middleware
- func (m Middleware) Code(pkg, funcName string) string
- func (m Middleware) H(w http.ResponseWriter, r *http.Request, p martini.Params)
- func (m Middleware) OnErr(handler interface{}) Middleware
- func (m Middleware) Provide(val interface{}) Middleware
- func (m Middleware) ProvideAs(val, ifacePtr interface{}) Middleware
- func (m Middleware) With(handlers ...interface{}) Middleware
- func (m Middleware) Wrap(before, after interface{}) Middleware
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Middleware ¶
type Middleware sandwich.Middleware
Middleware is the stack of middleware functions that powers sandwich's deliciousness. In addition to the default sandwich.Middleware, this supports the martini.Params type so you can get the route parameters in your handlers.
Martini expects a function rather than a particular interface, so use the .H accessor to get a martini-friendly handler.
func New ¶
func New() Middleware
New constructs a clean Middleware instance that provides martini's routing params (martini.Params), ready for you to start piling on the handlers.
func TheUsual ¶
func TheUsual() Middleware
TheUsual constructs a popular new Middleware instance with some delicious default handlers installed and ready to go: Request logging and simple error handling. It also provides martini's routing params (martini.Params).
func (Middleware) Code ¶
func (m Middleware) Code(pkg, funcName string) string
Code is the same as (sandwich.Middleware).Code.
func (Middleware) H ¶
func (m Middleware) H(w http.ResponseWriter, r *http.Request, p martini.Params)
H is the martini middleware handling function. You normally won't call this function directly but rather you'll pass it to martini.
func (Middleware) OnErr ¶
func (m Middleware) OnErr(handler interface{}) Middleware
OnErr is the same as (sandwich.Middleware).OnErr, but returns a martini_sandwich.Middleware.
func (Middleware) Provide ¶
func (m Middleware) Provide(val interface{}) Middleware
Provide is the same as (sandwich.Middleware).Provide, but returns a martini_sandwich.Middleware.
func (Middleware) ProvideAs ¶
func (m Middleware) ProvideAs(val, ifacePtr interface{}) Middleware
ProvideAs is the same as (sandwich.Middleware).ProvideAs, but returns a martini_sandwich.Middleware.
func (Middleware) With ¶
func (m Middleware) With(handlers ...interface{}) Middleware
With is the same as (sandwich.Middleware).With, but returns a martini_sandwich.Middleware.
func (Middleware) Wrap ¶
func (m Middleware) Wrap(before, after interface{}) Middleware
Wrap is the same as (sandwich.Middleware).Wrap, but returns a martini_sandwich.Middleware.