Skip to content

Instantly share code, notes, and snippets.

@EdgeCaseBerg
Created May 13, 2014 12:29
Show Gist options
  • Select an option

  • Save EdgeCaseBerg/d842ccae52c46a2eabc9 to your computer and use it in GitHub Desktop.

Select an option

Save EdgeCaseBerg/d842ccae52c46a2eabc9 to your computer and use it in GitHub Desktop.
http://tour.golang.org/#60 GoLang tutorial number 60
package main
import (
"fmt"
"net/http"
)
type String string
type Struct struct {
Greeting string
Punct string
Who string
}
func (h Struct) ServeHTTP(
w http.ResponseWriter,
r *http.Request) {
fmt.Fprint(w, h.Greeting, h.Punct, h.Who)
}
func (h String) ServeHTTP(
w http.ResponseWriter,
r *http.Request) {
fmt.Fprint(w, h)
}
func main() {
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