Source code
See The Go Programming Language/chapter1: server2, where two handlers are created to handle /
and /count
Symptom
Each time I visit /count
with Chrome, the counter
value is incremented too, while I would expect only the handler for the more specific path, /counter
to be called, which shouold not increment counter
.
Reason
- So my theory about the route matching rule is correct, see documentation for ServeMux.
- The reason why the
counter
is incremented when visiting/counter
is that the browser made a call to/favicon.ico
, which you can see from the Network inspection result that the/
handler is called.
Finding the Go documentation
Go has good documentation, accessible by hovering over the code in IDE.