4 ms·
You can easily handle route variables yourself with very simple logic. You can wrap http.HandleFunc to make it behave like middleware. You do not need to impo
by tyho 11y ago
You can easily handle route variables yourself with very simple logic.
You can wrap http.HandleFunc to make it behave like middleware.
You do not need to import a framework for these things:
https://vimeo.com/115940590 https://vimeo.com/115940590
- aikah 11y agoYes I can write an unmaintainable spaghetti mess, or I can isolate a specific business domain and write or use a library that solves this problem once and for all. Because at the end of the day it's me who end up testing and running that code, not you.
- belak 11y agoHave you seen Negroni? It provides a simple framework which solves some the middleware problem. It doesn't use dep injection, the code is more idiomatic and you can use it with any HTTP mux/router you want.
- nindalf 11y agoI think you ought to reconsider what the other guy said. His suggestions were quite good because they lead to simple, idiomatic code that relies solely on the standard library. You can read more here - https://medium.com/@matryer/the-http-handlerfunc-wrapper-technique-in-golang-c60bf76e6124 https://medium.com/@matryer/the-http-handlerfunc-wrapper-tec...
- aikah 11y agoI read matt ryer's excellent book "Go Blueprints" already. I know all that stuff. I use middlewares with complex logic, I write apps with hundreds of controllers, so with all due respect I'm not going to reinvent the wheel , each time I need to finish a project with tight deadlines. I don't understand this Go community mindset which says that "nothing is needed but the std lib". My use case isn't Google's or anybody else's. If the Go team wanted an idiomatic router or middleware stack well they should have provided fully featured ones in the standard lib. There are none. It means "user land".
- aikah 11y ago> You can easily handle route variables yourself with very simple logic. But you linked a talk that recommends a library to deal with route variables. > You can wrap http.HandleFunc to make it behave like middleware. But you linked a talk that recommends a library to deal with middlewares. Maybe you should review the links you post at first place.