News for hackers. Stuff that matters.
Re:Learning Go as a Node.js Developer by marcus_holmes on Thursday February 08, 2018 @11:57PM (#16337983)
You don't need a router (especially for an SPA with client-side routing). If you've got less than 20 or so routes, then a big switch statement is all the routing you need. Learning to write "proper" logic around routes instead of parsing them with regexes was a learning milestone for me.

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

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.
Re:Learning Go as a Node.js Developer by yur83838 on Friday February 09, 2018 @12:36AM (#16338129)
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.

Re:Learning Go as a Node.js Developer by dithering on Friday February 09, 2018 @01:56AM (#16338441)
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.
Re:Learning Go as a Node.js Developer by akmittal on Friday February 09, 2018 @12:39AM (#16338137)
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)

Re:Learning Go as a Node.js Developer by dithering on Friday February 09, 2018 @01:57AM (#16338444)
> some people prefer the framework magic because they want the stuff done faster.

Those people should try being maintenance programmers sometime /curmudgeonly-grumble

Re:Learning Go as a Node.js Developer by leaveyou on Friday February 09, 2018 @03:50AM (#16338807)
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.