标签:efi net hand Fix serve views 匹配 web 静态文件
对于 HTML 页面中的 css 以及 js 等静态文件,需要使用使用 net/http 包下的以下
方法来处理
1) StripPrefix 函数
2) FileServer 函数
3) 例如:
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("views/static"))))
/static/会匹配 以/static/开发的路径,当浏览器请求 index.html 页面中的style.css文件时,static前缀会被替换为views/staic,然后去views/static/cssstyle.css文件标签:efi net hand Fix serve views 匹配 web 静态文件
原文地址:https://www.cnblogs.com/ygjzs/p/12188800.html