I can't understand a part of the ResponseWriter
syntax.
type ResponseWriter interface {
Header() Header
Write([]byte) (int, error)
WriteHeader(statusCode int)
}
For instance, in the example provided in go by example, the area
method was implemented by both objects implementing geometry
interface.
The http.ResponseWriter
is an interface, which is capable of Write
, amongst other things.
I've written the following to test the value of w ResponseWriter
func sendData(w http.ResponseWriter, r *http.Request) {
fmt.Println(w)
}
func main() {
http.HandleFunc("/", sendData)
http.ListenAndServe(":8081", nil)
}
The returned result in a browser was blank
In the terminal where the code was executed, I obtained the following stdout:
&{0xc00009ebe0 0xc0000e8100 {} 0x112a550 false false false false 0xc00006c500 {0xc0000d40e0 map[] false false} map[] false 0 -1 0 false false [] 0 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0] [0 0 0] 0xc0000200e0 0}
Being an interface, it relies on the underlying type to do the actual writing but what is the underlying type and where is the write implemented?