猿问

http.HandleFunc 始终匹配“/”

代码:


http.HandleFunc("/", api.Index)

http.HandleFunc("/list", api.FileList)


http.HandleFunc("/api/upload", api.UploadFile)

http.HandleFunc("/api/delete", api.DeleteFile)


http.Handle("/files", http.StripPrefix("/files/", http.FileServer(http.Dir(settings.FilesPath))))


http.ListenAndServe(":1234", nil)

结果1:


http://localhost:1234/


http://localhost:1234/list


http://localhost:1234/文件


匹配 ”/”


api.index(第二个和第三个都错了)


结果 2:


http://localhost:1234/api/上传


http://localhost:1234/api/delete


匹配“/api/xxx”


api.xxx(没错)


环境:


去 1.13.5 windows/amd64


我应该怎么做才能解决这个问题?


翻过高山走不出你
浏览 219回答 1
1回答

不负相思意

尝试使用“/list/”替换“/list”更多信息:https ://pkg.go.dev/net/http?tab=doc#ServeMux
随时随地看视频慕课网APP

相关分类

Go
我要回答