martini_sandwich

package
v0.0.0-...-b39ab9c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2021 License: MIT Imports: 4 Imported by: 0

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

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL