go-web/main.go

26 lines
484 B
Go
Raw Normal View History

2024-09-05 14:23:58 +00:00
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))
}