Hmm for this example I would be more inclined to use an output parameter rather than generics
func Request(req, resp any) error {
// send request (http, etc)
b, err := json.Marshal(req)
if err != nil {
return err
}
log.Printf("sent request %+v - %s", req, b)
// read response
if err := json.Unmarshal([]byte(`{"success": false, "error": "invalid login"}`), resp); err != nil {
return err
}
return nil
}
But I kind of agree it's nicer to use a return value rather than an output parameter. I'm excited to see what other new uses people come up with for generics!