http.StripPrefix 的参数含义
看下面两行代码:
http.Handle("/file/", http.StripPrefix("/file", http.FileServer(http.Dir("./output/"))))
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./output/"))))
http.Handle("/file1", http.StripPrefix("/file1", http.FileServer(http.Dir("./output/"))))
http.Handle("/file2", http.StripPrefix("/file2/", http.FileServer(http.Dir("./output/"))))
注意看下图结果:
- 1、2 行链接地址是带对应前缀的。
- 3行链接地址不带
- 4直接 404




TrimPrefix
TrimPrefix returns s without the provided leading prefix string. If s doesn't start with prefix, s is returned unchanged.
StripPrefix
// StripPrefix returns a handler that serves HTTP requests
// by removing the given prefix from the request URL's Path
// and invoking the handler h. StripPrefix handles a
// request for a path that doesn't begin with prefix by
// replying with an HTTP 404 not found error.
func StripPrefix(prefix string, h Handler) Handler {
if prefix == "" {
return h
}
return HandlerFunc(func(w ResponseWriter, r *Request) {
if p := strings.TrimPrefix(r.URL.Path, prefix); len(p) < len(r.URL.Path) {
r.URL.Path = p
h.ServeHTTP(w, r)
} else {
NotFound(w, r)
}
})
}
如上图代码所示,
404 是触发了上面的 else 条件。
http.StripPrefix 的参数含义的更多相关文章
- paip.提升效率--调试--日志系统日志参数含义---python
paip.提升效率--调试--日志系统日志参数含义---python #同时向控制台和文件输出日志 #日志参数含义 import logging log_format = '%(filename)s ...
- (转)hadoop三个配置文件的参数含义说明
hadoop三个配置文件的参数含义说明 1 获取默认配置 配置hadoop,主要是配置core-site.xml,hdfs-site.xml,mapred-site.xml三个配 ...
- 机器学习——随机森林,RandomForestClassifier参数含义详解
1.随机森林模型 clf = RandomForestClassifier(n_estimators=200, criterion='entropy', max_depth=4) rf_clf = c ...
- C关键字typedef及argc,argv,env参数含义
C关键字typedef--为C中各种数据类型定义别名. 在此插一点C知识 int main(int argc,const char *argv[],const char *envp[])主函数的红色部 ...
- 百度搜索URL参数含义
序号 参数 含义 1 tn 搜索框所属网站.比如 tn=sitehao123,就是 http://www.hao123.com/ 左上那个搜索框(指通过什么方式到达百度首页搜索界面;) 2 s?wd ...
- php编译参数选项 具体参数含义可以用./configure --help来查看
php编译参数选项 PHP_INSTALL_PATH=/data/web/php MYSQL_INSTALL_PATH=/data/web/mysql ./configure --prefix=${ ...
- jQuery中Ajax事件beforesend及各参数含义1
jQuery中Ajax事件beforesend及各参数含义 转自:http://blog.sina.com.cn/s/blog_609f9fdd0100wprz.html Ajax会触发很多事件. 有 ...
- 802.11学习笔记1-WIFI参数含义
研究下wifi参数的含义 #The word of "Default" must not be removed Default CountryRegion= CountryRegi ...
- linux 设备树中 dwc3 节点的phys参数含义
找了好久今天找到了,记录一下: &dwc3_0 { ... phys = <&lane3 PHY_TYPE_USB3 1 2 26000000>; ... } Requir ...
随机推荐
- oracle sqlplus及常用sql语句
常用sql语句 有需求才有动力 http://blog.csdn.net/yitian20000/article/details/6256716 常用sql语句 创建表空间:create tables ...
- FASTDFS .net 客户端
FastDFS .net 客户端目前还比较少,而且使用大部分没有原生提供的方便 推荐一个比较方便的 下载地址: https://www.nuget.org/packages/NengLong.CMP. ...
- Flowplayer-一款免费的WEB视频播放器
Flowplayer 是一个开源(GPL 3的)WEB视频播放器.您可以将该播放器嵌入您的网页中,如果您是开发人员,您还可以自由定制和配置播放器相关参数以达到您要的播放效果. Flowplayer支持 ...
- Linux- Bond
---------------check NIC----------------- ①mii-tool 命令 ②ethtool 命令 -i 参数,显示网卡的驱动信息, -S 参数,底层工作状态信息③d ...
- html之br标签
<br>:自闭合 一般用法: 标签会告诉浏览器立即停止当前的文本流,并在下一行的左边继续输出,也通常用来在相临的段落之间制造一段垂直的间距. 代码: 效果: 问题:当段落中有表格或图片时怎 ...
- AJAX状态值与状态码
在<Pragmatic Ajax A Web 2.0 Primer > 0: (Uninitialized) the send( ) method has not yet been inv ...
- 如何通过SecureCRT FTP上传下载文件
通过SecureCRT FTP方式从一台机器下载文件到另一台机器上: [root@TEST144239 ~]# ftp 10.30.1.25 Connected to 10.30.1.25 (10. ...
- ADO.NET 拾遗
一.SqlDataReader和SqlDataAdapter性能对比 Stopwatch sw = new Stopwatch(); sw.Start(); using(SqlConnection c ...
- golang的ssh例子
package main import ( "github.com/dynport/gossh" "log" ) func MakeLogger(prefix ...
- 从官方下载 Bootstrap 版本 并写 第一个页面
从官方下载 Bootstrap 版本 页面内容参考自 http://www.cnblogs.com/sanjuantianshu/p/3935120.html bootstrap-3.2.0.zip ...