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:
http://localhost:8080/hello/world
from a browser/hello/world
http.HandleFunc("/hello/", handler)
and uncomment http.HandleFunc("/delete/", handler)
http://localhost:8080/delete/world
from a browser404 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.