首页 > Web开发 > 详细

goweb-处理静态资源

时间:2020-01-13 19:49:53      阅读:64      评论:0      收藏:0      [点我收藏+]

处理静态文件

对于 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/css
    目录中取查找 style.css文件

goweb-处理静态资源

原文:https://www.cnblogs.com/ygjzs/p/12188800.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!