3 ms·
It's there a "default" web framework for Go which most of people use?
by DeathArrow 3y ago
It's there a "default" web framework for Go which most of people use?
- imafish 3y agoMy intuition is that Golang people dislike frameworks.
- DeathArrow 3y agoSo they roll their own stuff each time they do a web app?
- maccard 3y agoA lot of go apps bolt together libraries yeah.
- giraffe_lady 3y agoFrom what I've seen yes. So in practice every go app is a custom & unique framework. Same problem as react. This was also the norm in php until laravel got popular a few years ago. IMO it's a rough way to make a web page but people keep doing it so it must have some advantages.
- rmilejczz 3y agoIt’s not that we roll all our own stuff it’s just that most of us avoid opinionated frameworks. Example I’d wager most go backends are using gorm or sqlx because rolling your own orm would be insane for most
- jamil7 3y agoNot a go dev but I have dabbled. I get the impression that the sweet spot for go is not in building standard crud web apps but for specialised network services and tooling. For those reasons big heavy frameworks don’t seem popular.
- Philip-J-Fry 3y agoComposition is king. The standard library defines some decent interfaces already around HTTP handling and SQL calls. Most libraries are built to integrate with them. Then interfaces like io.Reader and io.Writer mean you can pretty much use anything to read requests and write responses. This means that usually you're composing libraries and some application code together, rather than building everything on top of some jack of all trades framework. You get to choose the best tool for each job.
- kaba0 3y ago> Then interfaces like io.Reader and io.Writer mean you can pretty much use anything to read requests and write responses. Yeah, that’s not the hard part at all. What about routing, converting from/to json/params/cookies safely, sessions, authz/n..
- maccard 3y agoI'm a fan of gin over the builtins but: > What about routing, converting from/to json/params/cookies safely All supported out of the box with the standard library. It's also table stakes, and not the hard part. > sessions, authz/n This is where you need to step out of the standard
- out_of_protocol 3y agoYes and that's frustrating
- rollulus 3y agoYes, and it’s called net/http.
- tgv 3y agoAFAIK, no. There are some helper frameworks [1], but none of them is dominant. Two possible reasons: it's quite easy to write a (web) service with the library functions (it even includes a gzip stream), and it's practically impossible to write an ORM framework like you have in Java and Python, so the Go frameworks I've seen are basically a bunch of helper functions. [1] https://github.com/avelino/awesome-go#web-frameworks https://github.com/avelino/awesome-go#web-frameworks
- JodieBenitez 3y ago> impossible to write an ORM framework like you have in Java and Python genuinely interested in knowing why it is so. I quite like Go, but I also like Django, so I would like to know why a Django-like ORM would not be feasible.
- bkq 3y agoI have written about this some time ago here: https://andrewpillar.com/programming/2019/07/13/orms-and-query-building-in-go/ https://andrewpillar.com/programming/2019/07/13/orms-and-que... The main reason, in my opinion, comes down to how Go as a language was designed. I have written some follow up posts to that, specifically this one: https://andrewpillar.com/programming/2022/10/24/a-simple-crud-library-for-postgresql-with-generics-in-go/ https://andrewpillar.com/programming/2022/10/24/a-simple-cru... wherein I explore creating an ORM-like library via generics in Go, this may be of interest to you if you want a better understanding of how some of these things would work in Go.
- tgv 3y agoI thoroughly dislike Django. But if you look at how it works in Python, it's by taking over class definitions in such a way that a field can be both a description of the field and an actual value. That doesn't work in Go (explicit casting the fields at every place you use them could work, but is prone to errors). It "cleverly" overrules operators to turn something like the Python expression `age > 50` into the sql string `age > 50`. Can't be done in Go, unless you define functions for all operators and find a way to reflect on the field name and the current context (`gt("age", 50)`). That's a lot of work to turn one string into the same one. URLs can't be linked to a class by simply importing a file; you'd need to add quite a bit of scaffolding (a factory for each class with a common interface, I guess?). And there are other parts that rely on annotation and whatever that simply can't be ported to Go, so you'd have to turn them into function calls. And Django doesn't give you more than a glorified POST form app out of the box anyway. You have to add more views and serializers to turn it into a modern backend, so why not skip that and use libraries that implement the functionality you do need. Ok, my dislike shines through, but the gist is that Go doesn't let other code take over the interpretation of the meaning of expressions and statements and inject things into classes like Python does. It all has to be done explicitly. So django-like functionality for Go would have to look very different.
- leeman2016 3y agoNot "default(s)", but gin and fiber come to mind regarding popularity.
- sawirricardo 3y agoI also find myself reaching these!
- geordee 3y agoI would recommend to look at Iris-go
- bkq 3y agoI would recommend avoiding iris-go, the author has a bad history of rewriting the git history, and using code without attribution, see this for more: http://www.florinpatan.ro/2016/10/why-you-should-not-use-iris-for-your-go.html http://www.florinpatan.ro/2016/10/why-you-should-not-use-iri...
- lakomen 3y agoDownvoted because that guy steals other people's code without their permission.
- scns 3y agoNo default. There is Buffalo which is modeled after Rails, haven't used it in anger though. https://gobuffalo.io https://gobuffalo.io