4 ms·
How do you do session management in this GoTH stack? I am not proficient in Go, but I assume that you will go in two directions: 1. Either write the code for i
by gls2ro 2y ago
How do you do session management in this GoTH stack?
I am not proficient in Go, but I assume that you will go in two directions:
1. Either write the code for it yourself
2. Install a package
Here is where Rails shines: it comes with a battery included so for example, session management is as simple as doing:
session[:user_id] = user.id
User.find(session[:user_id])
I don't need to write my own code to handle this basic feature of a web app not do I have to decide what package to use.
Regarding the "modern" tech stack: What is so modern about Go + Templ + htmx?
Rails can work with htmx and has a wide range of templating options for HTML.
And if modern means static typing, I have bad news for you: types are old.
I don't want to say that GoTH is not a good stack. It could be a good stack, but choosing it because it is more modern than Rails is not the real reason.
> Too many outdated gems, too much magic, generators from gems doing who knows what with undo only possible because of Git
What gems have you tried? For building an API with Rails if that is what you can go a long way with Rails in API only mode.
- karolist 2y agoHey, thanks for the response. First off I want to say that Rails is not a bad stack if that's all you know, it definitely built tons of SaaS companies and that alone means you can go far with it, I'm not here to change your mind. It's also very fundamentally different from barebones Go approach where you do need to pick your modules, define your project structure and have a deeper understanding of request lifetime in general because you are supposed to manage it yourself, things like precise timeouts [1]. In Go, it is typical to do session management with middlewares, do JWT based auth, you can attach specific user info to request context so it is available to handlers post middleware actions. [2]. Go is very barebones with many control knobs and can throw people used to monoliths off, but it's really not that complicated and you don't need to write lots of code to handle things like sessions, post Go 1.22 the built in routing mechanism got good enough to not need any packages for that at all [3]. Regarding ORM, I've grown to dislike them eventually, even though I've used gORM which is very popular in Go land. Currently my SQL queries are handled by sqlc (example) [4] which compile the queries down to type safe Go code at build time. Types are old of course, and I didn't mean modern = GoTH or static typing, I guess modern in my comment was for node based frontend dev with React/Astro, I won't expand on this in this comment, it's getting long as is. Strong static typing is ridiculously good once you develop with it for a while, editor support and guarantees you get in the sense "if it compiles, it likely works" begin paying dividends soon after the project grows a bit. Not Rust level, you can write weakly typed Go if you want but that's not the default. I have type guarantees even through frontend/backend or backend-backend boundaries with gRPC/connect without writing any marshal/unmarshal code myself. Regarding outdated gems, I can't recall now, I tried looking up my history but didn't really find anything specific. I started with barebones with devise for auth and some redcarpet markdown parsing. I had troubles setting up hot reloading, AFAIK it should work OOB with Rails 7 but didn't, then I tried hotwire-livereload [5] which pulled in Redis but also worked sort of janky. Contrast that to how great Vite based project live reloads work for modern frontend or how simple and fast Go backends live reload with Air [6]. To end, if Rails works for you and you know Ruby already then it's a great stack, I didn't like certain things and magic and view Ruby as a dead end skill career wise so in the end I ended up not using it. I use Go daily at my dayjob so it makes sense to just use what I already know. 1. https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts https://blog.cloudflare.com/the-complete-guide-to-golang-net... 2. https://www.digitalocean.com/community/tutorials/how-to-use-contexts-in-go https://www.digitalocean.com/community/tutorials/how-to-use-... 3. https://go.dev/blog/routing-enhancements https://go.dev/blog/routing-enhancements 4. https://docs.sqlc.dev/en/latest/tutorials/getting-started-postgresql.html#schema-and-queries https://docs.sqlc.dev/en/latest/tutorials/getting-started-po... 5. https://github.com/kirillplatonov/hotwire-livereload https://github.com/kirillplatonov/hotwire-livereload 6. https://github.com/air-verse/air https://github.com/air-verse/air