Hi,

To serve static files,
you can use one of the many pre defined go http handlers,

  fs := http.FileServer(http.Dir("static"))
  http.Handle("/", fs)

found this article, among many others,
http://www.alexedwards.net/blog/serving-static-sites-with-go

Yes, that's a good point. Reading the bytes every time is not a good idea.

I suspect this code here
https://github.com/lutzhorn/shorturl/blob/master/db.go#L34
might be optimized to avoid cpu consumption.

If you d flood that url, that would trigger as many heavy computations as
req,
so all reqs will be impacted by the slow cpu,
including those not doing this computation (and that is where is the pb).

You might put that computation into a limited worker pool
to slow down only that url and not impact all the server.

Compuation of a a new hashid should only happen on a POST request inside NewURL. The newHashID is not named very good, it does not to the computation, it constructs an object that is then later used to make the actual computation. But I will keep an eye on this.

https://github.com/lutzhorn/shorturl/blob/master/db.go#L74
you might try something like this to avoid repeating the rollback on error,
https://play.golang.org/p/DC2S1nVD8U

That looks interessting.

Thanks!

Lutz

--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to