Go Web服务器无法正确处理/ delete /模式[关闭]

I just played with a google GO official example Writing Web Applications I tried to add a functionality to delete pages and it has not worked. The reason is that if you pass "/delete/" as a parameter to http.HandleFunc() function you get always 404 Page not found. Any other "foobar" string works as expected.

Simplified code:

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)
}

Steps to reproduce:

  1. Compile and call http://localhost:8080/hello/world from a browser
  2. Output is /hello/world
  3. Now comment http.HandleFunc("/hello/", handler) and uncomment http.HandleFunc("/delete/", handler)
  4. Compile and call http://localhost:8080/delete/world from a browser
  5. Result is 404 page not found, expected /delete/world

Question: Is there any special meaning for "/delete/" pattern? Is there any technical reason for that or is it just a bug?

This works fine here, and it cannot possibly work in one situation and not the other. You're just changing the string "hello" for the string "delete" between the two lines.

I suggest trying again more carefully. It must be a detail elsewhere.


The real reason was not checking the error result of ListenAndServe. An old copy was running in background, and the lack of error handling made it go unperceived. The browser was getting results from an old server.