看下面两行代码:

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 的参数含义的更多相关文章

  1. paip.提升效率--调试--日志系统日志参数含义---python

    paip.提升效率--调试--日志系统日志参数含义---python #同时向控制台和文件输出日志 #日志参数含义 import logging log_format = '%(filename)s ...

  2. (转)hadoop三个配置文件的参数含义说明

     hadoop三个配置文件的参数含义说明     1       获取默认配置 配置hadoop,主要是配置core-site.xml,hdfs-site.xml,mapred-site.xml三个配 ...

  3. 机器学习——随机森林,RandomForestClassifier参数含义详解

    1.随机森林模型 clf = RandomForestClassifier(n_estimators=200, criterion='entropy', max_depth=4) rf_clf = c ...

  4. C关键字typedef及argc,argv,env参数含义

    C关键字typedef--为C中各种数据类型定义别名. 在此插一点C知识 int main(int argc,const char *argv[],const char *envp[])主函数的红色部 ...

  5. 百度搜索URL参数含义

    序号 参数 含义 1 tn 搜索框所属网站.比如 tn=sitehao123,就是 http://www.hao123.com/ 左上那个搜索框(指通过什么方式到达百度首页搜索界面;) 2 s?wd ...

  6. php编译参数选项 具体参数含义可以用./configure --help来查看

    php编译参数选项  PHP_INSTALL_PATH=/data/web/php MYSQL_INSTALL_PATH=/data/web/mysql ./configure --prefix=${ ...

  7. jQuery中Ajax事件beforesend及各参数含义1

    jQuery中Ajax事件beforesend及各参数含义 转自:http://blog.sina.com.cn/s/blog_609f9fdd0100wprz.html Ajax会触发很多事件. 有 ...

  8. 802.11学习笔记1-WIFI参数含义

    研究下wifi参数的含义 #The word of "Default" must not be removed Default CountryRegion= CountryRegi ...

  9. linux 设备树中 dwc3 节点的phys参数含义

    找了好久今天找到了,记录一下: &dwc3_0 { ... phys = <&lane3 PHY_TYPE_USB3 1 2 26000000>; ... } Requir ...

随机推荐

  1. windows知识点

    https://technet.microsoft.com/zh-cn/windows/dd641430  win7相关资源 23. Remtoe FX是微软WIN2008 R2的SP1新功能首先您需 ...

  2. centos 安装 pip

    下载文件 wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate 执行安装 python get-pip.py

  3. hadoop(三):hdfs 机架感知

    client 向 Active NN 发送写请求时,NN为这些数据分配DN地址,HDFS文件块副本的放置对于系统整体的可靠性和性能有关键性影响.一个简单但非优化的副本放置策略是,把副本分别放在不同机架 ...

  4. ajax语法

    js语言功能比较强大,但不能访问数据库 ajax来补充这一缺陷 特点:输出不用刷新页面,条件查询数据显示页面上一般不用它,因为需要造很多表格不如用嵌入php代码方式简单 ajax语法: $.ajax( ...

  5. NAT,网络地址转换详解

    这个技术,是一个非常成熟的技术了,但是,为了将其弄得清楚点,体系点,也为了备忘,还是有必要在这里梳理一下! NAT:Network Address Translation. 这个主要是用在网络地址(I ...

  6. SPOJ #752. Power it!

    By property of mod operations , we can simply use Divide and Conquer + Recursion to solve it. Refere ...

  7. [dts]Device Tree格式解析

    转自:http://blog.csdn.net/airk000/article/details/21345159 目录: 1. 作用 2. 基本数据格式 3. 一些基本概念 4. 工作方式 a. 地址 ...

  8. activiti自定义流程之Spring整合activiti-modeler5.16实例(七):任务列表展示

    注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建        (2)创建流程模型:activiti自定义流程之Spring ...

  9. Titan-红号楼宗谱案例

    一. 简介 titan:存储,查询图形结构的数据库.分布式集群环境下,可支持数以千亿级别的点和边,同时支持上千个并发的实时的复杂图形遍历,支持ACID事务. 架构:支持以下3方面的自由组合 (1)节点 ...

  10. C#数字千分位问题

    1.C#中用最简单的方法把数字(不含小数)转换为千分位格式:     如1234567变成1,234,567 方法:1234567.ToString("###,###")   或  ...