我有這些處理程序:func StartHttpServer(ipAddr string) { mux := http.NewServeMux() mux.HandleFunc("/printJson", PrintJsonHandler) mux.HandleFunc("/report", RaportHandler) mux.HandleFunc("/returnBalancesDates", ReturnBalancesDatesHandler) mux.Handle("/", http.FileServer(http.Dir("./static"))) mux.Handle("/readfiles/", http.FileServer(http.Dir("./reports"))) err := http.ListenAndServe(ipAddr, mux) if err != nil { log.Fatal("ERROR: Http Server crashed: ", err) }}但似乎第二個 FileServer 處理程序沒有像我預期的那樣從文件夾“報告”返回文件
1 回答

寶慕林4294392
TA貢獻2021條經(jīng)驗 獲得超8個贊
按照您的設置方式,第二個文件服務器嘗試./reports/readfiles/file
在請求/readfiles/file
. 如果您希望它服務./reports/file
,請執(zhí)行以下操作:
mux.Handle("/readfiles/", http.StripPrefix("/readfiles/",http.FileServer(http.Dir("./reports"))))
- 1 回答
- 0 關注
- 103 瀏覽
添加回答
舉報
0/150
提交
取消