5 ms·
Would you say Go is suitable for web services and apps? I was trying to compare it with a rapid development framework like Rails but felt Go Web Frameworks aren
by princevegeta89 5y ago
Would you say Go is suitable for web services and apps?
I was trying to compare it with a rapid development framework like Rails but felt Go Web Frameworks aren't as mature and ready like Rails.
Any insight would be appreciated, thanks!
- pphysch 5y agoDefinitely suitable. Depends if you want to work within a framework or not. If you want a framework, use Rails/Django/Node as they are very mature. Huge plugin ecosystems, great for prototyping non-trivial features like authn, because a plugin certainly exists for it. If you want more control (fewer dependencies), roll everything yourself with Go. The built-in libraries are fantastic, you can spin up a CRUD app without any external libraries. There are also great third-party libraries, but I would stay away from framework-y stuff like GORM.
- princevegeta89 5y agoThanks. How about a framework which has all these things stitched together already? For example, a good templating engine and an ORM that supports DB migrations out of the box? Do we have one for Go?
- pphysch 5y agoGORM (https://gorm.io/index.html https://gorm.io/index.html) has auto migrations. But it is still a framework, which means it is making a lot of decisions for you and forcing you to learn its own way of doing things. Ultimately it is a relatively thin layer over builtin Go libraries like `html/template`, `net/http`, `database/sql`; generally speaking, the Go philosophy is to build systems yourself from these components and therefore keep the architecture simple, focused, and maintainable. Unless you are stuck with Go for a good reason, if you want a framework use one of the industry standard ones mentioned previously.
- petepete 5y agoI'd say that's not where its strength lies, but it's certainly possible. Building an API backend for a single page app though, absolutely.
- handrous 5y agoAFAIK nothing has the plug-n-play library availability of Rails, as far as things that are highly relevant to stitching together "web apps". Not even Django, which may be its closest competitor. That single aspect of it is so good that even though I hate Rails (but I think Ruby's alright—go figure) it's hard to recommend against it for some projects.
- nkozyra 5y agoTrue, but that's comparing a (light) framework to a language itself. Go is great for web services, it's the first thing I reach for.
- grey-area 5y agoYes. I've used Rails extensively before writing some larger sites in Go. Quick comparison of Go vs Rails: Pros: More performance, multi-threaded extremely capable web server built-in, culture of simplicity and low-dependencies, no breaking changes, goroutines, ideal for small services, static binaries (all deps included) so no need for rbenv, docker etc etc, no included JS, great stdlib (far better than Ruby's IMO), NO INHERITANCE. Cons: No standard structure others are familiar with, you'll need to find/write code for things like migrations, auth, rendering views, skeleton code generation. For things you need to find/write this may seem intimidating but it's an opportunity to explore the bits you liked about rails and jettison the bits you didn't like or need, and the stdlib includes a lot of what you need at a low level (e.g. html templating, crypto libs). I cannot emphasise the importance of no breaking changes, it's so refreshing compared to other language ecosystems like Ruby or JS. Overall I'm really happy with Go for web apps and would choose it again in a heartbeat, particularly over Ruby and Rails (which I also like, but has performance issues and cultural issues IMO).
- copperx 5y agoIs there a canonical ORM to use in Go, or would raw SQL be preferred?
- korginator 5y agoThere are ORMs available for Golang, but my experience has been better with packages like sqlx [1] or dat [2]. We've since been using SQLX for pretty much all DBMS related work, and regret nothing. In my experience SQLX gave us the right balance between abstraction and control. [1] http://jmoiron.github.io/sqlx/ http://jmoiron.github.io/sqlx/ [2] https://github.com/mgutz/dat https://github.com/mgutz/dat
- grey-area 5y agoNot really no, the lack of generics has hampered this as you can't easily return slices of arbitrary objects from an ORM so existing ORMs are pretty ugly. One way round this at present is code generation. From your comment I think you're talking about a query builder/executor though, which is a specific part of an ORM, they're pretty simple to build if that is your thing or there are a few examples of that out there. You're really just building up an sql string, storing params, adding a few helpers for things like joins and then executing. I personally use a query generator to generate consistent queries, and generated code per resource to create models from results.
- machiaweliczny 5y agoI suggest going Rails/Next.js/Django and then extracting Go microservices if you ever need it.
- princevegeta89 5y agoThis seems to be a really valid point
- dhagz 5y agoI only use Go for two things: CLIs and web services. There are a lot of frameworks out there to help you develop web services in Go, but what really impresses me is that you don't really need them - you can get surprisingly far just using the standard library.
- lawn 5y agoYou should also consider Elixir with Phoenix, as it's a comparable experience with Rails (although not as many libraries) while giving you much better performance. And Phoenix LiveView is just an incredible productivity boost, there's nothing quite like it.
- princevegeta89 5y agoHave been working a lot with Elixir lately. It's just that I wanted to see where Go stands