7Days/day1/base2/main.go

26 lines
450 B
Go
Raw Normal View History

2023-01-24 21:14:53 +08:00
package main
import (
"fmt"
"net/http"
)
type Engine struct{}
func (engine *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/":
fmt.Fprintf(w, "URL.Path = %q", r.URL.Path)
case "/hello":
for k, v := range r.Header {
fmt.Fprintf(w, "Header[%q] = %q", k, v)
}
default:
fmt.Fprintf(w, "404 NOT FOUND: %s", r.URL)
}
}
func main() {
engine := new(Engine)
http.ListenAndServe(":8000", engine)
}