对于 HTML 页面中的 css 以及 js 等静态文件,须要使用使用 net/http 包下的如下
方法来处理css
1) StripPrefix 函数
2) FileServer 函数html
3) 例如:
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("views/static"))))
浏览器
/static/
会匹配 以/static/
开发的路径,当浏览器请求 index.html
页面中的style.cs
s文件时,static
前缀会被替换为views/staic
,而后去views/static/css
style.css
文件