Implemented http server exercise
This commit is contained in:
parent
411e266c4d
commit
8c02a18ea6
28
exercises/05-http/go.go
Normal file
28
exercises/05-http/go.go
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user