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) +}