4 ms·
I don't know that I accept your premise. There are mainstream frameworks in Go, and there are people who write Python who also think you should eschew framework
by tptacek 9y ago
I don't know that I accept your premise. There are mainstream frameworks in Go, and there are people who write Python who also think you should eschew frameworks, so some of that is just fashion. What I think you can say is that Go programmers discourage frameworks that take your code out of compatibility with the net/http interfaces. This used to be a big deal, but ever since net/context was introduced, is less and less of one.
From a vantage point of being a consultant who reads a lot of people's Go code, the two things I see getting used a lot in real code are Gin, which is a full-on framework that historically hasn't been net/http compatible, and Gorilla, which is (and thus chooses not to call itself a framework at all). I think the difference between "toolkit" and "framework" is pretty academic.
In the rest of the web programming world, an according-to-Hoyle batteries-included "framework" ticks off the boxes for model, view, and controller, where "model" also provides persistence. For Django in Python and Rails in Ruby, which I think sort of set the standard for what we think about when we think of frameworks, this means an SQL-generating ORM of some sort. There are no good Go ORMs, so the frameworks you'll run into in Go tend not to do a whole lot more than providing a URL matcher/router and before/after middleware filters.
Security in Go web apps is good-news/bad-news. The good news is that the language itself forecloses on a bunch of security problems that are common in other languages; for instance, there's no eval() equivalent you can easily get to. The bad news is that because there isn't a standard ORM, you're more likely to have SQL injection than a comparable Django app would --- I still find SQLI in Go apps somewhat routinely, and virtually never find them in Django apps. Go's HTML templates do the same reasonable job of stopping XSS that every other modern framework does. You can get CSRF protection from any number of libraries (Gorilla provides one; so, I think, does Gin). It's especially straightforward to configure the "hygiene" security stuff like TLS/HSTS in Go, because of how closely server and application code is in Go.
Veering more into my own fashion sense, and so take this with a grain of salt: I find Go pretty painful to code interface and high-level presentation stuff in, and don't at all enjoy working in Go's html/template system. Rather than fight it, I just use Go to build JSON API code, and then deliver a React application as my only real HTML payload. In this design, basically all of the "user interface" stuff is delegated to ES6, and Go just handles the "model" and "controller" parts of MVC.
- pvg 9y agoGo just handles the "model" and "controller" parts of MVC. Or Go really handles the "model" part of "classical" MVC. I mention this just as kind of entertaining (to the sort of person that finds this kind of minutia entertaining) curiosity. The meaning of MVC - itself, of course, never a super-formally defined term - shifted somewhat to fit web apps but as web app technology got fancy enough to do (very nearly) oldschool MVC, the 'dumb web app' meaning of MVC is sticking around while 'smart web apps' do something much closer to OG MVC.