gpt4 book ai didi

Go Web 服务器无法正确处理/删除/模式化

转载 作者:数据小太阳 更新时间:2023-10-29 03:07:45 25 4
gpt4 key购买 nike

<分区>

我刚刚玩了一个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)
}

重现步骤:

  1. 在浏览器中编译并调用http://localhost:8080/hello/world
  2. 输出为/hello/world
  3. 现在注释 http.HandleFunc("/hello/", handler) 并取消注释 http.HandleFunc("/delete/", handler)
  4. 在浏览器中编译并调用http://localhost:8080/delete/world
  5. 结果是 404 找不到页面,应该是 /delete/world

问题:"/delete/" 模式有什么特殊含义吗?这有任何技术原因还是只是一个错误?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com