Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> why is the context returned from the errgroup instead of being an attribute?

It's a go style thing[1]. "Dont store context in a struct" is the general advice. Anybody seeing a ctx in a struct will flag the PR. I think golangci-lint does too.

The claim is that its confusing. Also you'll never see any std lib apis doing that. People just assume its a bad idea and don't do it. There are situations where it makes sense. Like operations that are described by a struct and you want to attach their context to those structs. A Boland developer will tell you "you're thinking in Java/Python/C#/JavaSctipt/etc you need to think in Go" and yes you can always rewrite the whole thing to be more go-like as in errgroup API. But it's just a style thing.

[1] https://go.dev/blog/context-and-structs



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: