为了账号安全,请及时绑定邮箱和手机立即绑定

http.HandleFunc 始终匹配“/”

http.HandleFunc 始终匹配“/”

Go
翻过高山走不出你 2022-04-26 19:37:51
代码: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/listhttp://localhost:1234/文件匹配 ”/”api.index(第二个和第三个都错了)结果 2:http://localhost:1234/api/上传http://localhost:1234/api/delete匹配“/api/xxx”api.xxx(没错)环境:去 1.13.5 windows/amd64我应该怎么做才能解决这个问题?
查看完整描述

1 回答

?
不负相思意

TA贡献1777条经验 获得超10个赞

尝试使用“/list/”替换“/list”

更多信息:https ://pkg.go.dev/net/http?tab=doc#ServeMux


查看完整回答
反对 回复 2022-04-26
  • 1 回答
  • 0 关注
  • 218 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号