From 8c02a18ea67f08e674e1687c173ef29ade807f0f Mon Sep 17 00:00:00 2001 From: "Stephen M. McQuay" Date: Tue, 28 Aug 2012 21:54:04 -0600 Subject: [PATCH] Implemented http server exercise --- exercises/05-http/go.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 exercises/05-http/go.go diff --git a/exercises/05-http/go.go b/exercises/05-http/go.go new file mode 100644 index 0000000..6307b06 --- /dev/null +++ b/exercises/05-http/go.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "net/http" +) + +type String string + +func (s String) ServeHTTP(w http.ResponseWriter, r *http.Request) { + fmt.Fprint(w, s) +} + +type Struct struct { + Greeting string + Who string + Punct string +} + +func (s Struct) ServeHTTP(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "%v %v%v", s.Greeting, s.Who, s.Punct) +} + +func main() { + http.Handle("/string/", String("I am a freaking zealot.")) + http.Handle("/struct/", Struct{"hello", "world", "!"}) + http.ListenAndServe("localhost:4000", nil) +}