I tried to post this review on gitbooks.io, but couldn't. So I guess I'll put this up here:<p>This is a great introduction to building web apps in Go. (I started roughly two months ago, but had this book been around, I'd have been brought up to speed a lot faster).<p>Here's why: the predominant approach to building web apps in Go is to build on top of standard interfaces (e.g. net/http), and to keep things as simple as possible. Heavy, prescriptive frameworks are frowned upon. This is a great approach, but probably strange to people (like me) who come from prescriptive frameworks like Rails or Django.<p>Jeremy's guide sticks to Go conventions, while respectfully suggesting lightweight libraries that complement this approach. The guide is never "YOU MUST USE THIS", instead it always introduces the bare-bones approach first, and then tells you "hey, there's a 3rd party library that gives you some useful shortcuts on top of those." And indeed, each of the recommended libraries are idiomatic and easy to understand.<p>My review is probably biased, though, because I now have some idea now of how to write web apps in Go. But I certainly wished this book had existed when I first started.
I run a simple Go server behind Apache for my weekend project (<a href="http://www.thespanishsite.com" rel="nofollow">http://www.thespanishsite.com</a>). I started with this blog:<p><a href="http://www.jeffreybolle.com/blog/run-google-go-web-apps-behind-apache" rel="nofollow">http://www.jeffreybolle.com/blog/run-google-go-web-apps-behi...</a><p>I also use MySql on Digital Ocean with a $10/month droplet. The few issues at first where that I started with a $5/month which didn't enough RAM so I'd run out of memory until I created swap:<p><a href="https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04" rel="nofollow">https://www.digitalocean.com/community/tutorials/how-to-add-...</a><p>Still need to make it a daemon, but I'm not finished. I have one big method to set up my pages. I could write a blog, github repo or create a summary page on my site, if there's any interest.<p>func runWeb() {<p><pre><code> serveSingle("/robots.txt", "./robots.txt")
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("./css/"))))
http.Handle("/resources/", http.StripPrefix("/resources/", http.FileServer(http.Dir("./resources/"))))
http.Handle("/static", http.FileServer(http.Dir("./static/")))
http.HandleFunc("/chinese", chineseHomeHandler)
http.HandleFunc("/french", frenchHomeHandler)
http.HandleFunc("/chinese/numbers", chineseNumbersHomeHandler)
// Many handlers deleted ...
http.HandleFunc("/", homeHandler)
// http.ListenAndServe("localhost:9999", nil)
port := GetPort()
fmt.Println("listening...", port)
err := http.ListenAndServe(port, nil)
if err != nil {
panic(err)
}</code></pre>
}<p>/*
<a href="http://stackoverflow.com/questions/14086063/serve-homepage-and-static-content-from-root" rel="nofollow">http://stackoverflow.com/questions/14086063/serve-homepage-a...</a>
<i>/<p>func serveSingle(pattern string, filename string) {<p><pre><code> http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, filename)
})
}</code></pre>
Thanks for the feedback guys! The book is still a work in progress. It started as curriculum for the workshop I gave a couple days ago at DotGo. The plan is to continue making it awesome and to make the examples more complete.
Aren't there a lot of required packages to build a webapp? I would recommend against using any of those at least in the beginning. Maybe gorilla/mux, but even that can be avoided.<p>Don't just add deps you will never use, it's going to make your life painful.
The hard-coded dependencies on GitHub (not to mention they're dependencies to code owned by someone else) have always bothered me. It seems like it would create a real problem for compiling, auditing, or even just testing code in the long run; and this example relies on a ton of them.<p>I haven't kept up with the state of the art Go packaging; have these problems been addressed?
I don't mean to be a bit difficult here, but i wonder if the tutorial's author had anybody actually try it. I mean it seems like there's tons of missed steps, sections missing, assumed bits which aren't done. Each example i try tends to have other things done, uh, as exercises for the reader, which are required before the code samples even work.
Is using gorilla/context really the only easy way to store an retrieve data that is specific to the current HTTP request? Seems like there should be a better way to map values and retrieve them later from a global mutex on a map of request objects, or something.