Re:Learning Go as a Node.js Developer
by jjoonathan on Friday February 09, 2018 @12:34AM
(#16338119)
I still remember the first time I had to pick apart a gigantic chunk of java code and found a big switch statement at the center instead of a web of introspectively discovered implicitly wired reactively chained bean factory factory factories or some such nonsense. The relief was almost palpable.
You don't need a router, but it is much more readable with one.
You don't need middleware, but it is much more readable with r.Use(jwtVerify) then writing a deeply nested half router with logic.
If you're running a single endpoint, then the router is adding zero value.
Readability is, I think, a function of your expectations. If you're used to seeing a particular incantation, it's readable. Personally (emphasis on the personally, which is my point), I don't think it gets much more readable that a great big switch statement.
I see Go community pushing for no framework everywhere. I agree Go std library is good enough but some people prefer the framework magic because they want the stuff done faster.
Community should better be saying try std library if you find it verbose try framework(router+ORM)
> some people prefer the framework magic because they want the stuff done faster.
Those people should try being maintenance programmers sometime /curmudgeonly-grumble
I agree with everything you said except the websocket.. the best websocket lib for golang until now is https://github.com/gorilla/websocket
Re:Learning Go as a Node.js Developer
by marcus_holmes on Friday February 09, 2018 @07:27AM
(#16339683)
It's getting to the point where the Gorilla packages could be considered part of the standard library ;)
I agree, but the point is that you can do this with just the "almost official" package. It's not like you have to use the gorilla package because there's no standard library package.
You don't need an ORM. Mapping database tables to objects directly is a really bad idea. Write SQL, it's easy, simple and cheap. Yes, you'll repeat yourself. Golang generally prefers some repetition to some dependency.
You don't need middleware. Once you get used to handling routes as logic, then the need for middleware kinda vanishes.
You can use the semi-official google websockets package [0]. It's borderline whether this could be considered part of the standard library or not (I use the google uuid package all the time for the same reason). I believe there's an intention to include these packages in the standard library at some point, probably Go v2.
Try it out, it's liberating.
0: https://godoc.org/golang.org/x/net/websocket