Finishing the http handlers exercise
(hopefully)
This commit is contained in:
parent
d9a4c3a2e7
commit
ad41085cd3
@ -1,9 +1,32 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type String string
|
||||||
|
|
||||||
|
type Struct struct {
|
||||||
|
Greeting string
|
||||||
|
Punct string
|
||||||
|
Who string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s String) ServeHTTP(
|
||||||
|
w http.ResponseWriter,
|
||||||
|
r *http.Request) {
|
||||||
|
fmt.Fprintf(w, "%s\n", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Struct) ServeHTTP(
|
||||||
|
w http.ResponseWriter,
|
||||||
|
r *http.Request) {
|
||||||
|
fmt.Fprintf(w, "%s%s %s", s.Greeting, s.Punct, s.Who)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
http.Handle("/string", String("I'm a frayed knot."))
|
||||||
|
http.Handle("/struct", &Struct{"Hello", ":", "Gophers!"})
|
||||||
http.ListenAndServe("localhost:4000", nil)
|
http.ListenAndServe("localhost:4000", nil)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user