1
0
Fork 0

Implemented http server exercise

This commit is contained in:
Stephen M. McQuay 2012-08-28 21:54:04 -06:00
parent 411e266c4d
commit 8c02a18ea6
1 changed files with 28 additions and 0 deletions

28
exercises/05-http/go.go Normal file
View File

@ -0,0 +1,28 @@
package main
import (
"fmt"
"net/http"
)
type String string
func (s String) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, s)
}
type Struct struct {
Greeting string
Who string
Punct string
}
func (s Struct) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "%v %v%v", s.Greeting, s.Who, s.Punct)
}
func main() {
http.Handle("/string/", String("I am a freaking zealot."))
http.Handle("/struct/", Struct{"hello", "world", "!"})
http.ListenAndServe("localhost:4000", nil)
}