3 ms·
The context package didn't exist when Gin was created, so they invented their own solution. There was a proliferation of these context types until the standard
by grose 4y ago
The context package didn't exist when Gin was created, so they invented their own solution. There was a proliferation of these context types until the standard library created a common solution. chi uses it, but Echo doesn't. The biggest advantage is that the stdlib context key type is interface{}, so you can use unexported types to create private key namespaces. It's also immutable and thread-safe. Gin and Echo use plain strings that are easy to clobber. This blog post discusses how the stdlib context works: https://go.dev/blog/context https://go.dev/blog/context (see userip bit about the unexported types).
In many ways, Echo is a "better Gin".
- JodieBenitez 4y agoThanks for taking the time to explain. I see Gin can expose the stdlib context: router.GET("/", func(context *gin.Context) {context.Request.Context()}) > In many ways, Echo is a "better Gin". Interesting. I find it difficult to compare the plethora of web frameworks in Go. But coming from Python, I'm also familiar to this kind of situation...