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

That is what Gin does.


No, that's exactly the opposite of what it does. The article above explicitly criticizes gin for not returning a value.

Echo is closer to the pattern described above, but:

1. Echo lets you return an error response, but doesn't let you customize how the error is rendered _in a modular way_. You can only have a single global custom error handler that decides how to serialize the errors, and it needs to have knowledge of how to properly serialize every kind of error in your app. I have to admit this is generally good enough for most of the apps, and I don't think you can do any better in Go, considering it doesn't have type classes like Rust. The best that you can do is to let errors implement a CustomHttpRenderer interface on their own and try to cast into it — but this is already doable with a custom error renderer in Echo.

2. Echo doesn't let you return a non-error Response from the handler - instead it's written directly to the ReponseWriter. This approach makes writing unit tests several orders of magnitude harder and also means you can forget to write a successful response in some cases. You can also both write a response directly and return an error, which cannot result in a valid behavior (Echo will take the safe route and just ignore the error code and do nothing).


Axum isn't returning anything, IntoResponse outputs to HTTP. The error type in a handler is Infallible.


Gin is excellent. It's the right balance of batteries included, sensible defaults, and black magic


You don't return anything in Gin.




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

Search: