Skip to content

Instantly share code, notes, and snippets.

@freeformz
Created July 14, 2012 18:12
Show Gist options
  • Save freeformz/3112430 to your computer and use it in GitHub Desktop.
Save freeformz/3112430 to your computer and use it in GitHub Desktop.
My GoTour Exercise #58b (http://localhost:3999/#58) solution
package main
import (
"net/http"
)
type String string
type Struct struct {
Greeting string
Punct string
Who string
}
func (s String) ServeHTTP(rw http.ResponseWriter, request *http.Request) {
rw.Write([]byte(s))
return
}
func (s Struct) ServeHTTP(rw http.ResponseWriter, request *http.Request) {
rw.Write([]byte(s.Greeting + s.Punct + " " + s.Who))
return
}
func main() {
// your http.Handle calls here
http.Handle("/string", String("I'm a frayed knot."))
http.Handle("/struct", &Struct{"Hello", ":", "Gophers!"})
http.ListenAndServe("localhost:4000", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment