2012-10-18 13:17:47 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2012-11-06 02:00:35 +00:00
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2012-10-18 13:17:47 +00:00
|
|
|
)
|
|
|
|
|
2012-10-23 22:22:34 +00:00
|
|
|
type String string
|
|
|
|
|
|
|
|
type Struct struct {
|
2012-11-06 02:00:35 +00:00
|
|
|
Greeting string
|
|
|
|
Punct string
|
|
|
|
Who string
|
2012-10-23 22:22:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s String) ServeHTTP(
|
2012-11-06 02:00:35 +00:00
|
|
|
w http.ResponseWriter,
|
|
|
|
r *http.Request) {
|
|
|
|
fmt.Fprintf(w, "%s\n", s)
|
2012-10-23 22:22:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2012-10-23 22:22:34 +00:00
|
|
|
}
|
|
|
|
|
2012-10-18 13:17:47 +00:00
|
|
|
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)
|
2012-10-18 13:17:47 +00:00
|
|
|
}
|