go - 将 http.Handler 放入马提尼酒中

标签 go martini

如何像 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 26commit a945713static.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/

相关文章:

go - 如何跳过 Go 中文件的第一行?

go - 像 Django 一样在文件更改时重新启动 Go 的 net/http 服务器

arrays - 创建一个没有 make 的 Go slice

go - 是否可以在不触发竞争条件的情况下检查是否已设置字段?

mongodb - 使用 mgo.Monotonic 从中学读取

go - 在 martini.Context 中获取请求 url

data-binding - 将结构传递给 Post martini 例程

go - 如何将golang类型结构中的列类型定义为longtext?

go - 类型接口(interface){}不支持索引

go - 安装 Go from source to custom prefix