It's shorter, but it's harder for me to grasp what it does as easily as the first example.
On Wednesday, August 10, 2016 at 2:09:58 AM UTC-7, Anmol Sethi wrote: > > You can shorten that by 6 lines > > package main > > import "net/http" > > func main() { > http.ListenAndServe(":8080", http.HandlerFunc(func(w > http.ResponseWriter, r *http.Request) { > w.Write([]byte("Hello World!")) > })) > } > > A bare bones web server in just 9 lines! > > > On Aug 10, 2016, at 3:53 AM, gary.wi...@victoriaplumb.com <javascript:> > wrote: > > > > Hi, > > > > I'm giving a talk at work introducing Go and I'm looking for small > examples to show Go's potential. For example, the following program > demonstrates a bare-bones webserver in 13 lines: > > > > import ( > > > > "fmt" > > "net/http" > > ) > > > > func home(w http.ResponseWriter, r *http.Request) { > > fmt.Fprintf(w, "Hello, world!") > > } > > > > func main() { > > http.HandleFunc("/", home) > > http.ListenAndServe(":8080", nil) > > } > > > > Has anyone here got any more little snippets like this to show the power > and potential of Go? It doesn't have to be in networking, just little a > little snippet to make people think "wow, that's cool!". > > > > Thanks. > > > > > > > > -- > > 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...@googlegroups.com <javascript:>. > > For more options, visit https://groups.google.com/d/optout. > > -- 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.