我正在玩一個小型玩具服務(wù)器來學(xué)習(xí) Go 網(wǎng)絡(luò)編程。我的項目目錄結(jié)構(gòu)有以下public目錄:public\ | style.css上的權(quán)限public和style.css是r-x和r--每個人。在main.go,我有以下幾行:router := mux.NewRouter()router.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("public"))))log.Fatal(http.ListenAndServe(":3001", router))每次我調(diào)用http://localhost:3001/static/style.css 服務(wù)器時都會返回 404。我已經(jīng)嘗試了路徑中前導(dǎo)和尾隨斜杠的所有組合,但沒有任何區(qū)別。我在 Ubuntu 15.10 (x64) 上運(yùn)行 Go v1.5.3。
1 回答

喵喔喔
TA貢獻(xiàn)1735條經(jīng)驗 獲得超5個贊
下面是一個示例,說明如何/static/從名為public.
router := mux.NewRouter()
//router.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("public"))))
router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("public/"))))
log.Fatal(http.ListenAndServe(":3001", router))
- 1 回答
- 0 關(guān)注
- 156 瀏覽
添加回答
舉報
0/150
提交
取消