gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 02:16:17 24 4
gpt4 key购买 nike

如何像 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com