Go web server does not process /delete/ pattern correctly -
i played google go official example writing web applications tried add functionality delete pages , has not worked. reason if pass "/delete/"
parameter http.handlefunc()
function 404 page not found. other "foobar"
string works 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 reproduce:
- compile , call
http://localhost:8080/hello/world
browser - output
/hello/world
- now comment
http.handlefunc("/hello/", handler)
, uncommenthttp.handlefunc("/delete/", handler)
- compile , call
http://localhost:8080/delete/world
browser - result
404 page not found
, expected/delete/world
question: there special meaning "/delete/"
pattern? there technical reason or bug?
this works fine here, , cannot possibly work in 1 situation , not other. you're changing string "hello"
string "delete"
between 2 lines.
i suggest trying again more carefully. must detail elsewhere.
the real reason not checking error result of listenandserve
. old copy running in background, , lack of error handling made go unperceived. browser getting results old server.
Comments
Post a Comment