Why handler is called twice?

Hi,

when I hit the URL ,the handler is called twice.

Code:
package main

import (
“net/http”
)

type CustomHandler int

func (handler CustomHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request){
println(“the handler”)
}

func main() {
handleallRequests()
//http.ListenAndServe(“8081” , nil)
}

func handleallRequests() {
var handler CustomHandler
http.ListenAndServe(":8081", handler)
}

2 Likes

If you use curl, you will see that it is actually called once. Your browser also requests favicon.ico and as your handler doesn’t handle this properly, it replies with the same response (it actually logs the same message).

3 Likes

yes. thank you

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.