我刚刚玩了一个谷歌 GO 官方示例编写 Web 应用程序我试图添加一个功能来删除页面,但它没有奏效。原因是如果你"/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 page not found
,预期的/delete/world
问:"/delete/"
pattern
有什么特殊含义吗?有什么技术原因还是只是一个错误?