It is said that interface{}
represents any type in Go. For example, let us consider a Marshal
function in encoding/json
which is used to convert Go data structure into a JSON string. Its definition is
func Marshal(v interface{}) ([]byte, error)
But we are passing a struct to it as a parameter like below.
type hello struct{
Message string
}
data,err:= json.Marshal(hello{Message:'Hello world'})
How is Go handling this?