You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
543 B
33 lines
543 B
12 years ago
|
package main
|
||
|
|
||
|
import (
|
||
12 years ago
|
"fmt"
|
||
|
"net/http"
|
||
12 years ago
|
)
|
||
|
|
||
12 years ago
|
type String string
|
||
|
|
||
|
type Struct struct {
|
||
12 years ago
|
Greeting string
|
||
|
Punct string
|
||
|
Who string
|
||
12 years ago
|
}
|
||
|
|
||
|
func (s String) ServeHTTP(
|
||
12 years ago
|
w http.ResponseWriter,
|
||
|
r *http.Request) {
|
||
|
fmt.Fprintf(w, "%s\n", s)
|
||
12 years ago
|
}
|
||
|
|
||
|
func (s Struct) ServeHTTP(
|
||
12 years ago
|
w http.ResponseWriter,
|
||
|
r *http.Request) {
|
||
|
fmt.Fprintf(w, "%s%s %s", s.Greeting, s.Punct, s.Who)
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
func main() {
|
||
12 years ago
|
http.Handle("/string", String("I'm a frayed knot."))
|
||
|
http.Handle("/struct", &Struct{"Hello", ":", "Gophers!"})
|
||
|
http.ListenAndServe("localhost:4000", nil)
|
||
12 years ago
|
}
|