Did any #Go developers need code to get a zero value of a struct but without knowing the layout of the struct itself?
The only thing I could come up with was:
func zero[T any](v T) T {
 z := &v
 zz := reflect.ValueOf(z).Elem()
 zz.Set(reflect.Zero(reflect.TypeOf(v)))
 return *z
}
And see here an example of usage: https://go.dev/play/p/Aqzc_nRzOcP
I needed it in order to get zero copies of random structs so I could test that some marshal/unmarshal functionality is a bijection.
Is this a decent way to do it? Are there alternatives?
 
      
  
            