Re: [go-nuts] uber handler to collect stacktrace when program crashing

2022-05-27 Thread Ian Lance Taylor
On Fri, May 27, 2022 at 10:42 AM Aggarwal Sre wrote: > > Is there a recommended pattern besides adding a defer call ( with recover > call, to collect debug stack trace) to each goroutine, for collecting a stack > trace when a golang is crashing due to any sort of panic. > > In other words, is th

[go-nuts] uber handler to collect stacktrace when program crashing

2022-05-27 Thread Aggarwal Sre
Hi , Is there a recommended pattern besides adding a defer call ( with recover call, to collect debug stack trace) to each goroutine, for collecting a stack trace when a golang is crashing due to any sort of panic. In other words, is there a way to register an uber handler ( probably using OS sig

Re: [go-nuts] Generics

2022-05-27 Thread 'Sebastien Binet' via golang-nuts
what you may be looking at is (in the words of Rog Peppe) "structural type constraints": https://go.dev/play/p/HiFc9CUfI7P -s On Fri May 27, 2022 at 18:32 CET, Martin Schnabel wrote: > the reason your snippet does not work is that you pass in *payload as T > and the zero value of a pointer type

Re: [go-nuts] Generics

2022-05-27 Thread Martin Schnabel
the reason your snippet does not work is that you pass in *payload as T and the zero value of a pointer type is nil and json unmarshal cannot with nil pointer values. so would need to pass in payload as T and *payload as P and somehow explain that P is *T and a encoding.BinaryUnmarshaler. I am

Re: [go-nuts] Generics

2022-05-27 Thread Martin Schnabel
how about https://go.dev/play/p/YXOTLKpvXNI using json unmarshal directly and without using binary marshaller. or even https://go.dev/play/p/GFE3rnyx9f8 without the endpoint abstraction. or maybe explain what you want to achieve other than unmarshalling a json payload? best regards On 5/27/

[go-nuts] Generics

2022-05-27 Thread Jérôme LAFORGE
Hello, I do some tests with generics with Go 1.18. But I can't reach my goal. With https://go.dev/play/p/7kxMEWtXcPG I have: ``` panic: json: Unmarshal(nil *main.payload) goroutine 1 [running]: main.main() /tmp/sandbox3884661607/prog.go:43 +0x112 Program exited. ``` Because payload (li