如何像 http.FileServer
一样与 martini 集成?
`包主
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()
}`
最佳答案
我相信 FileServer 没有直接在 Martini 中使用:参见 issues/20 :
Unfortunately The fileserver middleware throws a 404 if there is no match, which means we will need to roll our own
因此 PR 26和 commit a945713在 static.go
你可以在 static_test.go
中看到
m := New()
r := NewRouter()
m.Use(Static(currentRoot))
m.Action(r.Handle)
关于go - 将 http.Handler 放入马提尼酒中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28814114/