While studying net/http
I actually wanted to know that how go returns http.Response
to listener. From this answer, I found that http.Response type is passed to ServeHTTP, but that is not the case because on compilation below code throw error. Which means http.Response
does not implement http.ResponseWriter
interface. I am curious what is the type which implements http.ResponseWriter
interface?
# command-line-arguments
./server1.go:9:20: http.Response.Header is a field, not a method
./server1.go:9:20: impossible type assertion:
http.Response does not implement http.ResponseWriter (missing Header method)
func handler(resp http.ResponseWriter, req *http.Request){
actualresp := resp.(http.Response) //https://tour.golang.org/methods/15
resp.Write([]byte("Hello Web, from go"))
}
func main(){
http.HandleFunc("/api", handler)
http.ListenAndServe(":8000", nil)
}