码迷,mamicode.com
首页 > Web开发 > 详细

goweb-处理静态资源

时间:2020-01-13 19:43:57      阅读:103      评论:0      收藏:0      [点我收藏+]

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

goweb-处理静态资源

标签:efi   net   hand   Fix   serve   views   匹配   web   静态文件   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!