Challenge 3 — Solution Task: Write a function fetchUser(id int) (User, error) that fetches from https://jsonplaceholder.typicode.com/users/{id}, unmarshals into a User struct with at least Name and Email fields (with json tags), properly closing the response body with defer. Call it and print the result, handling any error. package main import ( "encoding/json" "fmt" "io" "net/http" ) type User struct { Name string `json:"name"` Email string `json:"email"` } func fetchUser(id int) (User, error) { var user User resp, err := http.Get(fmt.Sprintf("https://jsonplaceholder.typicode.com/users/%d", id)) if err != nil { return user, err } defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { return user, err } err = json.Unmarshal(body, &user) return user, err } func main() { user, err := fetchUser(1) if err != nil { fmt.Println("Error:", err) return } fmt.Println(user.Name) fmt.Println(user.Email) } Expected output: Leanne Graham Sincere@april.biz Notes: - defer resp.Body.Close() is placed immediately after confirming err is nil from http.Get — this guarantees the body gets closed once fetchUser returns, regardless of whether the later ReadAll or Unmarshal steps succeed or fail. - fetchUser returns the (possibly still-empty) user struct alongside any error at each early-return point, matching the same multi-return-value pattern from Fundamentals Chapter 5. - The User struct only defines Name and Email — the real API response includes many more fields (address, phone, etc.), but json.Unmarshal simply ignores any JSON fields that don't have a matching struct field.