httpgoglide-golang

*http.http2gzipReader vs io.ReadCloser Golang


In the defination of the source code of response.go it is defined that the Body of type io.ReadCloser but while printing the type of Body by the following code it prints *http.http2gzipReader. Are they both same?

package main

import (
    "fmt"
    "net/http"
)

func main() {
    //any url
    url := "https://www.goal.com/en-in"
    res, _ := http.Get(url)
    body := res.Body
    fmt.Printf("tpye is %T", body)
}


Solution

  • No, they are not same.

    io.ReadCloser interface is the type of request body but the *http.http2gzipReader is the concrete type assigned to the interface. That's what we call, *http.http2gzipReader implements io.ReadCloser interface.