我是新手,如果這是一個明顯的問題,那么抱歉,但我沒有找到任何東西,所以我在這里發帖。這實際上是一個由兩部分組成的問題。1)所以我的項目目錄中有這個Web文件夾。它是公共的,我有一個中間件功能來檢查 JWT。我正在使用此邏輯來避免 JWT 身份驗證,但它現在可以正常工作。我明白了unauthorized。// List of endpoints that don't require auth by an access token notAuth := []string{"/", "/refreshtokens", "/students/signup", "/students/signin", "/students/forgotpassword", "/images"} // Current request path requestPath := r.URL.Path // Check if the request does not need authentication, serve the request if it doesn't need it for _, value := range notAuth { if value == requestPath { next.ServeHTTP(w, r) return } }那么我怎樣才能把這個URL放入數組中,這樣它就可以逃脫JWT授權呢?2)這就是我公開文件夾的方式,但我不想要這樣。router.PathPrefix("/images").Handler(http.StripPrefix("/images", http.FileServer(http.Dir("./web/"))))我想要的是類似的東西router.Handle("/image/{imageName}",func(w http.ResponseWriter, request *http.Request){http.ServeFile(this image name file)})這樣我就可以發回所請求的文件。任何幫助將不勝感激。
1 回答

白衣非少年
TA貢獻1155條經驗 獲得超0個贊
對于#1:顯然請求路徑不是notAuth
. notAuth
也許您需要檢查路徑是否具有包含在?中的前綴。如果是這樣,你需要小心/
,因為它會通過所有路徑。如果沒有,記錄請求路徑并查看問題所在。
對于#2:你應該能夠做到:
http.ServeFile(w,request,filepath.Join(baseDir,mux.Vars(request)["imageName"])
- 1 回答
- 0 關注
- 137 瀏覽
添加回答
舉報
0/150
提交
取消