hi,

some more sharings,

like val said, https://github.com/lutzhorn/shorturl/blob/master/main.go#L42 
is not optimum,

get ride of the anonymous func is obvious.
Note: that would have been useful in a loop iteration that spawns go 
routine.

To go beyond, I think you can do, signatures seems to match from here.

http.HandleFunc("/index.html", handler.Index)

when index is invoked, it will keep its receiver.


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


Based on that i suspect some changes will happen into handler.Root.

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.

But, maybe this hashing is very fast, i don t know about that.


https://github.com/lutzhorn/shorturl/blob/master/db.go#L63
this is tricky to make better in place, but it smells useless complexity.

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

I also invite you to also check packages like dbr or gorm to handle the DB.



On Tuesday, May 2, 2017 at 9:32:45 AM UTC+2, Lutz Horn wrote:
>
> Hi Go Nuts, 
>
> to practice my Go skills, I've implemented a simple web application that 
> allows you to shorten an URL. The application consists of a backend 
> written in Go and a web frontend using jQuery with some plugins and 
> Bootstrap for layout. 
>
> The code is available on GitHub at https://github.com/lutzhorn/shorturl, 
> the application is deployed on https://u.lhorn.de. 
>
> I would very much appreciate any feedback you can give especially on the 
> Go part. Coming from a Java and Python background, I'm trying to get 
> into the Go way of programming, In Python there is a 'Pythonic' way to 
> write code, I am sure there is something similar in Go: File structure, 
> name choice, exporting names, error handling, ... 
>
> If you have a little time, please tak a look at the code, play with the 
> deployed application, and please give me feedback. 
>
> 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