8 ms·
Show HN: A HN clone writen in Go
I've been trying to write my "go on rails" framework for years. I never quite got it like I wanted. There is gin and echo and all sorts of other frameworks and patterns but I finally found something I really like:
/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 https://github.com/andrewarrow/feedback
- lowbar 4y agoRSS would be a cherry on top :)
- DeathArrow 4y agoI wonder what language and framework HN is using.
- djmips 4y agohttp://arclanguage.org/forum http://arclanguage.org/forum
- ksec 4y ago>"go on rails" You should take a look at Crystal and Lucky.
- andrewfromx 4y agoI tried to google for both, do you have links?
- Zanni 4y agoCrystal: https://crystal-lang.org/ https://crystal-lang.org/ Lucky: https://luckyframework.org/ https://luckyframework.org/
- andrewfromx 4y agoohh i see why my google search failed, I was adding the word "go" or "golang" because I thought these were GO rails frameworks.
- icholy 4y agoDon't do this: https://github.com/andrewarrow/feedback/blob/90abc793edd0806235c6d902ce40a91dbda33024/router/new.go#L27 https://github.com/andrewarrow/feedback/blob/90abc793edd0806...
- deleted 4y ago[deleted]
- andrewfromx 4y agooh, yes, that code isn't even used anymore. Fix pushed.
- wffurr 4y agoThe real secret sauce to HN would be cloning dang.
- Jabrov 4y agoLLM-based dang clone? Hmm…
- quickthrower2 4y agoAnd patio11 &tc
- papa-whisky 4y agoMega nitpick and completely off topic; it's just "&c". "Et" translates as "and" which can be replaced by the ampersand, "cetera" is "the rest".
- bqmjjx0kac 4y agoMy understanding is that "&" is actually a ligature of "Et". You can kind of see it if you squint your eyes!
- kanbara 4y agoyup this is correct
- 4y ago
- bqmjjx0kac 4y agoIs there an advantage to limiting the route to three components? It feels limiting, and I'm not really sure what it buys you.
- krapp 4y agoI mean, HN only has one and everything else is query params.
- imoverclocked 4y agoWhenever I see code like the example routing, I have to wonder if a hash lookup would be more appropriate. This is especially when all the functions called are of exactly the same form, I immediately just want an interface for that and then define a map from “first” to handler. 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?
- hombre_fatal 4y agoWhen routing is static, it's trivial and any solution will work. Like when your routes are all static /foo/bar and they merely use ?query params to pass info. 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/show
- l_theanine 4y agoI’d love something like this just for python. Especially sans HN style moderation.
- TekMol 4y agoIf there was a Django based HN clone in Python, I would be tempted to run an instance for topics I am interested in.
- anaganisk 4y agoBut who is going to visit your site? I dont mean to make a snarky comment, but I am curious as to how data is generated?
- app4soft 4y agoWorth to add in the title: > An HN clone written in Go with Google's telemetry[0] [0] https://news.ycombinator.com/item?id=34744948 https://news.ycombinator.com/item?id=34744948
- nvknfhnvd 4y agoNo, a build time option that can be disabled is not relevant to the post 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.
- mseepgood 4y agoAlso, the current plan is that it would be opt-in. You'd have to explicitly enable it.
- nottorp 4y ago> Also, the FUD you linked to says the feature MAY be shipped. 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.
- saagarjha 4y agoThere is no Google telemetry in the site. Pattern matching on “Go” with whatever your recent issue is with it is a bad comment.
- kitd 4y agoGood job. 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.
- cactusplant7374 4y agoSomeone once said, "It's good for simple projects but projects rarely stay simple." That's why I like frameworks and the batteries that they include.
- ilyt 4y agoSometimes you need batteries, not a nuclear plant bigger frameworks come from
- sethammons 4y agoWhat is an example of something simple vs complex? 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.
- donio 4y agoSimple composable components are especially important for complex projects. The larger the project the less likely that the assumptions made by the framework will be a good fit for it.
- cactusplant7374 4y ago
- denysvitali 4y agoSo meta: https://remoterenters.com/stories/57cf0737-f8ed-6cf3-542d-2c0afe433af5/ https://remoterenters.com/stories/57cf0737-f8ed-6cf3-542d-2c...
- sideproject 4y agoAwesome! Last week, I released "Launch your own HN-Clone" tool https://www.hn.plus https://www.hn.plus 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!
- chinaman425 4y ago[dead]
- dzink 4y agoNice work. Here is some 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.
- itake 4y ago2/ encrypt your ids before rendering them and decrypt them for queries. No need to store a huge string when int64 does the exact same. Also, nothing wrong with incremental ids. Twitter and fb are doing just fine.
- sethammons 4y agoNot exposing user ids is a good thing. UUIDs may be a bad thing depending on needs. They cause poor locality in storage which can increase seek time.
- ilyt 4y ago> 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. 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"
- _8j50 4y agoVery funny: https://remoterenters.com/stories/57cf0737-f8ed-6cf3-542d-2c0afe433af5/ https://remoterenters.com/stories/57cf0737-f8ed-6cf3-542d-2c... 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.
- DeathArrow 4y agoJudging by minuses I get on my comments sometimes, there's no shadowban on HN. And I was never limited in trying to post reply.
- _8j50 4y agoLucky me then. When you get enough downvotes, it kicks in and sticks for weeks
- teleforce 4y agoThanks for posting this will check it out. It'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 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.
- Thaxll 4y agoBecause Go and other "modern" programming language don't want heavy framework like Rails, Spring, Django etc ... It's not a struggle it's a choice. Light and composable libraries are the way to go not heavy framework.
- skee8383 4y agonice but font is a bit small.
- everybodyknows 4y agoiPad's text size adjustment control works perfectly.
- skee8383 4y agocringe
- Semaphor 4y agoI thought that was very fitting, just like with HN, I immediately zoomed in ;)
- rcarmo 4y agoCan’t read any comments - I have an ad blocker on, so I suspect it’s JS? Should be all static.