Skip to content

Instantly share code, notes, and snippets.

@sevkin
Created April 11, 2014 20:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sevkin/10497657 to your computer and use it in GitHub Desktop.
Save sevkin/10497657 to your computer and use it in GitHub Desktop.
custom middleware for martini
func Vermut() *martini.ClassicMartini {
r := martini.NewRouter()
m := martini.New()
m.Use(martini.Logger())
m.Use(martini.Recovery())
// pass cached images to thumbnailer
m.Use(NewThumbnailer("public"))
cache := martini.NewRouter()
cache.Group("/cache", cacheHandler)
cache.NotFound(func() {})
m.Use(cache.Handle)
// then serve generated (and not) thumbs by static
m.Use(martini.Static("public"))
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
return &martini.ClassicMartini{m, r}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment