26 lines
484 B
Go
26 lines
484 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"html"
|
||
|
"log"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
type FooHandler struct{}
|
||
|
|
||
|
func (foo FooHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||
|
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
var fooHandler FooHandler
|
||
|
http.Handle("/foo", fooHandler)
|
||
|
|
||
|
http.HandleFunc("/bar", func(w http.ResponseWriter, r *http.Request) {
|
||
|
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
|
||
|
})
|
||
|
|
||
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
||
|
}
|