Why handler is called twice?


(Gowtham Girithar) #1

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


(Boban Acimovic) #2

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


(Gowtham Girithar) #3

yes. thank you