2020
12-18
12-18
在go文件服务器加入http.StripPrefix的用途介绍
例子:http.Handle("/tmpfiles/",http.StripPrefix("/tmpfiles/",http.FileServer(http.Dir("/tmp"))))当访问localhost:xxxx/tmpfiles时,会路由到fileserver进行处理当访问URL为/tmpfiles/example.txt时,fileserver会将/tmp与URL进行拼接,得到/tmp/tmpfiles/example.txt,而实际上example.txt的地址是/tmp/example.txt,因此这样将访问不到相应的文件,返回404NOTFOUND。因此解决方案就是把URL中的/tmpfiles/去掉,而http.S...
继续阅读 >