2014-11-24 141 views
0

我需要設置位於「公共」文件夾中的默認頁面「index.html」。我如何在Martini框架中做到這一點?如何在Martini中設置默認靜態頁面?

我tryed這一點,但它不工作:

func main() { 
    m := martini.Classic() 
    static := martini.Static("public", martini.StaticOptions{Fallback: "/index.html", Exclude: "/send"}) 
    m.NotFound(static, http.NotFound) 
    m.Use(static) 
    m.Get("/send", sendEmail) 
    m.Run() 
} 

回答

0

你做正確。檢查您是否確實有index.html in public/文件夾,並且它是可訪問的。

當前,如果回退文件不可訪問,則會默默丟棄錯誤。

+0

我笑了。索引,html在公用文件夾中。 屏幕截圖:https://yadi.sk/i/5r0_k_UTcv5WW – Pavel 2014-11-25 07:26:24

+0

你如何運行你的應用程序,你會得到什麼錯誤? 這裏是我對你的代碼的測試(index.html在我的例子中包含「Hello,World」):http://imgur.com/2aI0TMO – divan 2014-11-25 07:42:46