Search code examples
gomartini

Put the http.Handler in martini


How do I integrate just like http.FileServer with martini? ` package main

import (
    "github.com/go-martini/martini"
    "net/http"
)

func main() {
    m := martini.Classic()
    //http.Handle("/", http.FileServer(http.Dir("."))) //It doesn't work!
    m.Run()
}`

Solution

  • I believe the FileServer isn't used directly in Martini: see issues/20:

    Unfortunately The fileserver middleware throws a 404 if there is no match, which means we will need to roll our own

    Hence PR 26 and commit a945713 in static.go that you can see in static_test.go

    m := New()
    r := NewRouter()
    m.Use(Static(currentRoot))
    m.Action(r.Handle)