Settings

Theme

Show HN: link shortening API in Go

rdhq.co

16 points by jnye131 12 years ago · 14 comments

Reader

redbad 12 years ago

    import (
    	"./utils"
This is what's known as a relative import, and it's very bad. You want "github.com/johnnye/short/utils", or (better yet) put your base62 stuff in package main, since it's just one function.
  • jnye131OP 12 years ago

    Cheers, I knew it wasn't very "go like" at the time. Will go and tidy it up at the weekend.

  • malandrew 12 years ago

    go discourages relative imports? interesting. why? Are these files not packaged together?

tekacs 12 years ago

Whilst they are nonetheless interesting and worth seeing, there really does seem to be an abundance of really small (30-200 SLoC) projects being posted and reaching the front page recently. I'm just curious because I'd usually consider these sorts of things ~20 minutes' work (plus potentially a more meaningful amount of time writing the documentation). They stand out to me in this sense amongst all the blog posts and stories which almost invariably will have taken a great deal more time and effort to produce. [1]

Any thoughts? Indeed any prior discussion?

[1]: Not to say that this isn't a nice idea. :)

  • jnye131OP 12 years ago

    Yep, I've noticed that sorry to propagate a trend that isn't the best. I think it's because you can do quite a lot in an afternoon with Go especially if your learning, like me.

    • tekacs 12 years ago

      Oh yes, absolutely. I just wonder when I see these posts if I should post similar small apps that I built along the way to learning some new technology or language and then, so far, decide that it's probably not the most useful.

      On the other hand, given that I myself often end up using those small learning apps for a few years after I built them (even tiny apps can be useful day-to-day), perhaps that's not a fair assessment.

betamike 12 years ago

Very cool. If you have a recent enough version of Redis, you may want to move away from doing the lookup using KEYS and move to SCAN (http://redis.io/commands/scan). KEYS will work for a while, but with a large enough DB it can become a very slow operation so it's not typically recommended for a production system.

Also, just curious, I see that the original url is encoded in the key, so the key is "<short>||<original>". Since the key is already a hash, it seems that you could eliminate having to scan over every key in Redis by making each key be only "<short>" and having an additional field in the hash for "original". Then a lookup becomes simply an HGETALL (if you need to get the "count" field, otherwise just an HGET for the "original" field). I might be missing something though! </armchair programming>

  • jnye131OP 12 years ago

    By encoding the original URL in the key you can look up to see if a URL has been shortened already, and serve that.

    Thanks for the info re scan I'll have a look and check my version of redis.

drsintoma 12 years ago

> 502 Bad Gateway

I believe your go process crashed. Consider using something like runit or supervisord.

  • laumars 12 years ago

    A Go webserver shouldn't need supervisord. If the program is crashing then that's a sign of a more serious exception which needs to be fixed (eg unsafe global variables) as most other exceptions will just force a stack dump but keep the parent process running.

  • jnye131OP 12 years ago

    It did, it's back up, I will. Thanks

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection