msgpack icon indicating copy to clipboard operation
msgpack copied to clipboard

Why NewDecoder return zero response ?

Open restuwahyu13 opened this issue 2 years ago • 0 comments

Why NewDecoder return zero value ?, and not return value from jph, but if i try with json encoding, i'm get response back from jph like this {1 Leanne Graham [email protected]}.

Code

package main

import (
	"fmt"
	"net/http"

	"github.com/vmihailenco/msgpack/v5"
)

type Person struct {
	ID    int    `json:"id"`
	Name  string `json:"name"`
	Email string `json:"email"`
}

func main() {
	payload := Person{}

	fetch, _ := http.Get("https://jsonplaceholder.typicode.com/users/1")
	msgpack.NewDecoder(fetch.Body).Decode(&payload)
	defer fetch.Body.Close()

	fmt.Println(payload)
}

Response

{0  }

restuwahyu13 avatar Jun 20 '22 15:06 restuwahyu13