<分区>
我刚刚玩了一个google GO官方例子Writing Web Applications我试图添加删除页面的功能,但没有成功。原因是,如果您将 "/delete/"
作为参数传递给 http.HandleFunc()
函数,您总是会收到 404 Page not found。任何其他 "foobar"
字符串都按预期工作。
简化代码:
package main
import (
"fmt"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "%s", r.URL.Path)
}
func main() {
http.HandleFunc("/hello/", handler)
//http.HandleFunc("/delete/", handler)
http.ListenAndServe(":8080", nil)
}
重现步骤:
- 在浏览器中编译并调用
http://localhost:8080/hello/world
- 输出为
/hello/world
- 现在注释
http.HandleFunc("/hello/", handler)
并取消注释http.HandleFunc("/delete/", handler)
- 在浏览器中编译并调用
http://localhost:8080/delete/world
- 结果是
404 找不到页面
,应该是/delete/world
问题:
"/delete/"
模式有什么特殊含义吗?这有任何技术原因还是只是一个错误?