天天看點

【錯誤記錄/go】通路golang靜态伺服器路由出現404錯誤錯誤詳情解決

錯誤詳情

  • 想要使用不同的路由規則作為靜态檔案伺服器時,通路不到
    127.0.0.1/common
               
    package main
    
    import (
    	"net/http"
    )
    
    func main() {
    	http.Handle("/common/", http.FileServer(http.Dir("./test")))
    	http.ListenAndServe(":8080", nil)
    }
               

解決

  • test

    目錄下沒有

    common

    檔案夾
  • 正确的目錄結構應該是這樣子的
    127.0.0.1/common
               
    那麼結構如下
    ----test
          |
          ----common
                |
                1.txt
               

繼續閱讀