From ad41085cd39b6a2353bbf1f07313e4e752b01375 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Tue, 23 Oct 2012 18:22:34 -0400 Subject: [PATCH] Finishing the http handlers exercise (hopefully) --- gotime/src/exercise-http-handlers.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/gotime/src/exercise-http-handlers.go b/gotime/src/exercise-http-handlers.go index f1f5062..e66cc29 100644 --- a/gotime/src/exercise-http-handlers.go +++ b/gotime/src/exercise-http-handlers.go @@ -1,9 +1,32 @@ package main import ( + "fmt" "net/http" ) +type String string + +type Struct struct { + Greeting string + Punct string + Who string +} + +func (s String) ServeHTTP( + w http.ResponseWriter, + r *http.Request) { + fmt.Fprintf(w, "%s\n", s) +} + +func (s Struct) ServeHTTP( + w http.ResponseWriter, + r *http.Request) { + fmt.Fprintf(w, "%s%s %s", s.Greeting, s.Punct, s.Who) +} + func main() { + http.Handle("/string", String("I'm a frayed knot.")) + http.Handle("/struct", &Struct{"Hello", ":", "Gophers!"}) http.ListenAndServe("localhost:4000", nil) }