115 points · by andrewfromx · 3y ago · 65 comments
/foo/
/foo/bar/
/foo/bar/more/
That's it. Just three levels and all my controllers get passed in what's between the / with var names first, second, third.
In order to really make sure this framework could build something real I made a Hacker News clone. RemoteRenters.com is a HN just for articles about the remote work revolution since covid. Feel free to vote or submit to see how it all works!
Code is open source at: https://github.com/andrewarrow/feedback
1. Go has a major bottleneck and that’s the growth of its memory size when it’s under pressure. Templates bloat the memory quickly and make the site less performant at scale (aka if you put it on Heroku, you’d need more Dinos to support the traffic, which costs more.). Instead of GO templating, you can produce static pages and fill them up with JS Ajax or React, or whatever your front end flavor is and make that call a Go API you produce with the framework instead. This also helps you turn your site into an app if needed as well.
2. Saw somewhere you had database incremented user ids and other models? Not safe as it allows any bad actor to peruse your user base. Always do UUID as a scramble that can’t be iterated on.
Keep hammering. For everyone who says you don’t need a framework in Go, there are at least a few newbies who learn how to set up and run their Go server and stack from your framework.
It will most likely be fast enough. If not there are libs that will compile your templates to Go code with very minimal overhead, or templating libraries that are much faster than builtin one.
I'd think adding megabytes of JS garbage just to run site would be opposite of "HN clone"
As for "working at scale", this post itself is id ~35 million. You could likely fit all of that into ram on a modestly sized server.
This. A million times this. Please don't be discouraged by any negative responses you get here.
Look at HN for example. Everything is public and they use incrementing ids for posts and comments.
Also, nothing wrong with incremental ids. Twitter and fb are doing just fine.
Do you have any references where one could read up on such issues and how to navigate them?
any resources or benchmark numbers to back this claim?
As an alternative view though, one of the nice things about Go, or specifically the http part of the stdlib, is that it composes well with libraries and middleware like Chi or Negroni. So rather than having to conform to an all-encompassing web framework, you can assemble just the tools you need for the problem at hand.
Whenever something is no longer simple, it is more work to customize them than it would have been to write something yourself, with judicious use of more specific libraries as opportunistically effective. That seems to present itself rather quickly every time I decide to test out a new framework.
I believe my services' APIs count as simple. HTTP verbs, url and query parameters, some auth headers and jwts, json payloads, and http error codes usually with a json body. As such, all my problems are easily solved with the chi package. I don't do much form handling as our UI handles that and uses our APIs. FWIW, our APIs handle billions of requests per day.
What is complex? I imagine things around templating, forms, and maybe (maybe!!) auth. Is that what drives framework advocates?
My past experience with a few were that they made simple things simple and hard things harder or impossible. I abandoned them about a decade ago however, so could be out of touch.
The counter point in some languages (eg: Java) is that switch statements/expressions handle it this way under the hood at compile time depending on if it’s more efficient to use a map or a bunch of checks.
What is the actual best practice in go these days?
Not sure what you're asking, but handling dynamic segment routing ergonomically is where naive solutions tend to fail.
For example, a simple trie/map router needs additional logic to backtrack and try downstream routes. You wouldn't want `GET /users/42/show` to 404 in the following route table.
/users/42/admin
/users/:id/showIt's very interesting that you've mentioned that you're trying to create "go on rails" and the fact that there are already similar other frameworks in go.
The author of Stanza language has this insightful article on the viability of a programming language for creating a powerful framwork like Ruby on Rails:
Stop Designing Languages. Write Libraries Instead:
http://lbstanza.org/purpose_of_programming_languages.html
It's very interesting because until today after more than 10 years of existence, not unlike Java, Go is still struggling to have a popular and robust framework ala Rails for its community.
Python has Zope and then Django to compete with Rails and I think they're the turning point for its rapidly increasing popularity about 20 years ago in the face of its potent programming language competitors at the time including Java, Ruby, TCL, Perl, C#, etc.
It's not a struggle it's a choice. Light and composable libraries are the way to go not heavy framework.
I've tried to maintain true to most of the HN features and also included other features so you can grow your HN-clone community!
I can't see the topic/title in the URL which makes clicking always risky.
I hope you have better rate limits than HN, where I would post something and can't reply to present my argument to others because I posted like 4 timed in an hour. That and I hope you have no shadowban features. May open and respectful discourse prosper.
You should take a look at Crystal and Lucky.
> An HN clone written in Go with Google's telemetry[0]
Do you pedantically point out that end users have to accept Oracle's end user license agreement to install the JRE when someone posts something written in Java, or that mp3s are patent encumbered when someone posts a music player? For crying out loud
Also, the FUD you linked to says the feature MAY be shipped. It hasn't even actually happened.
Go away.
Doesn't it worry you that they'd even consider this kind of stuff?
Also, a proposal by one of their developers is not FUD. Maybe suicide.