box-o-sand/oldstuff/gotime/gotour-artifacts/exercise-http-handlers/main.go

33 lines
543 B
Go
Raw Normal View History

package main
import (
2012-11-06 02:00:35 +00:00
"fmt"
"net/http"
)
type String string
type Struct struct {
2012-11-06 02:00:35 +00:00
Greeting string
Punct string
Who string
}
func (s String) ServeHTTP(
2012-11-06 02:00:35 +00:00
w http.ResponseWriter,
r *http.Request) {
fmt.Fprintf(w, "%s\n", s)
}
func (s Struct) ServeHTTP(
2012-11-06 02:00:35 +00:00
w http.ResponseWriter,
r *http.Request) {
fmt.Fprintf(w, "%s%s %s", s.Greeting, s.Punct, s.Who)
}
func main() {
2012-11-06 02:00:35 +00:00
http.Handle("/string", String("I'm a frayed knot."))
http.Handle("/struct", &Struct{"Hello", ":", "Gophers!"})
http.ListenAndServe("localhost:4000", nil)
}