dongluo1853 2017-06-27 14:18
浏览 59
已采纳

http.FileServer发送“找不到404页”

I'm trying to serve static files via http.FileServer, however it never sends back the directory I'm asking for. The code is snipped below:

func main() {

fmt.Println("Serving Files")
http.HandleFunc("/", homeFunc)
http.HandleFunc("/search", searchFunc)
http.Handle("/tmp/",
    http.StripPrefix("/tmp/", http.FileServer(http.Dir("/assets"))))

http.ListenAndServe(":8080", nil)
}

When visiting mywebsite.com/tmp/, text appears saying "404 page not found." A little help in case I'm missing something would be greatly appreciated!

Edit: Here's the file architecture:

main folder
|
|-/Assets
|--(assets)
|
|-main.go
  • 写回答

1条回答 默认 最新

  • doumo1807831 2017-06-27 14:52
    关注

    Does the directory /assets exist? Note that /assets is an absolute path, so it must be at the root of your filesystem. If you want something in the working directory where you're executing your program, you should use ./assets.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后的密码
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 UE5#if WITH_EDITOR导致打包的功能不可用
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题