Collapsing tree into more sane Go project layout
since I was in here looking at something unrelated...
This commit is contained in:
32
gotime/gotour-artifacts/exercise-http-handlers/main.go
Normal file
32
gotime/gotour-artifacts/exercise-http-handlers/main.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"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() {
|
||||
http.Handle("/string", String("I'm a frayed knot."))
|
||||
http.Handle("/struct", &Struct{"Hello", ":", "Gophers!"})
|
||||
http.ListenAndServe("localhost:4000", nil)
|
||||
}
|
Reference in New Issue
Block a user