TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Building Web Apps with Go

302 pointsby linhmtran168over 10 years ago

11 comments

shadowsun7over 10 years ago
I tried to post this review on gitbooks.io, but couldn&#x27;t. So I guess I&#x27;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&#x27;d have been brought up to speed a lot faster).<p>Here&#x27;s why: the predominant approach to building web apps in Go is to build on top of standard interfaces (e.g. net&#x2F;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&#x27;s guide sticks to Go conventions, while respectfully suggesting lightweight libraries that complement this approach. The guide is never &quot;YOU MUST USE THIS&quot;, instead it always introduces the bare-bones approach first, and then tells you &quot;hey, there&#x27;s a 3rd party library that gives you some useful shortcuts on top of those.&quot; 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.
评论 #8448328 未加载
评论 #8448069 未加载
评论 #8449938 未加载
评论 #8447989 未加载
mellingover 10 years ago
I run a simple Go server behind Apache for my weekend project (<a href="http://www.thespanishsite.com" rel="nofollow">http:&#x2F;&#x2F;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:&#x2F;&#x2F;www.jeffreybolle.com&#x2F;blog&#x2F;run-google-go-web-apps-behi...</a><p>I also use MySql on Digital Ocean with a $10&#x2F;month droplet. The few issues at first where that I started with a $5&#x2F;month which didn&#x27;t enough RAM so I&#x27;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:&#x2F;&#x2F;www.digitalocean.com&#x2F;community&#x2F;tutorials&#x2F;how-to-add-...</a><p>Still need to make it a daemon, but I&#x27;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&#x27;s any interest.<p>func runWeb() {<p><pre><code> serveSingle(&quot;&#x2F;robots.txt&quot;, &quot;.&#x2F;robots.txt&quot;) http.Handle(&quot;&#x2F;css&#x2F;&quot;, http.StripPrefix(&quot;&#x2F;css&#x2F;&quot;, http.FileServer(http.Dir(&quot;.&#x2F;css&#x2F;&quot;)))) http.Handle(&quot;&#x2F;resources&#x2F;&quot;, http.StripPrefix(&quot;&#x2F;resources&#x2F;&quot;, http.FileServer(http.Dir(&quot;.&#x2F;resources&#x2F;&quot;)))) http.Handle(&quot;&#x2F;static&quot;, http.FileServer(http.Dir(&quot;.&#x2F;static&#x2F;&quot;))) http.HandleFunc(&quot;&#x2F;chinese&quot;, chineseHomeHandler) http.HandleFunc(&quot;&#x2F;french&quot;, frenchHomeHandler) http.HandleFunc(&quot;&#x2F;chinese&#x2F;numbers&quot;, chineseNumbersHomeHandler) &#x2F;&#x2F; Many handlers deleted ... http.HandleFunc(&quot;&#x2F;&quot;, homeHandler) &#x2F;&#x2F; http.ListenAndServe(&quot;localhost:9999&quot;, nil) port := GetPort() fmt.Println(&quot;listening...&quot;, port) err := http.ListenAndServe(port, nil) if err != nil { panic(err) }</code></pre> }<p>&#x2F;* <a href="http://stackoverflow.com/questions/14086063/serve-homepage-and-static-content-from-root" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;14086063&#x2F;serve-homepage-a...</a> <i>&#x2F;<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>
评论 #8448888 未加载
评论 #8448823 未加载
评论 #8449194 未加载
codegangstaover 10 years ago
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.
humanfromearthover 10 years ago
Aren&#x27;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&#x2F;mux, but even that can be avoided.<p>Don&#x27;t just add deps you will never use, it&#x27;s going to make your life painful.
评论 #8447942 未加载
评论 #8447918 未加载
akbar501over 10 years ago
It would be helpful for Go newbies if a 3rd column (description) was added to the table in the &quot;Required Packages&quot; section.
评论 #8449555 未加载
john2xover 10 years ago
If there&#x27;s one thing Go did right, it&#x27;s the logo&#x2F;mascot. (sorry for OT)
评论 #8448116 未加载
评论 #8449074 未加载
评论 #8448812 未加载
评论 #8448142 未加载
falcolasover 10 years ago
The hard-coded dependencies on GitHub (not to mention they&#x27;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&#x27;t kept up with the state of the art Go packaging; have these problems been addressed?
评论 #8448581 未加载
rabbleover 10 years ago
I don&#x27;t mean to be a bit difficult here, but i wonder if the tutorial&#x27;s author had anybody actually try it. I mean it seems like there&#x27;s tons of missed steps, sections missing, assumed bits which aren&#x27;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.
评论 #8452504 未加载
preillymeover 10 years ago
Is using gorilla&#x2F;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.
JoeAcchinoover 10 years ago
Is this guide specific for Go on Heroku or its concepts can be easily applied elsewhere?
评论 #8448135 未加载
krat0sprakharover 10 years ago
This looks awesome! Thanks a lot, Jeremy for doing this and sharing it with us!