30 lines
483 B
Go
30 lines
483 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
// Engine 定义一个结构体
|
|
type Engine struct {
|
|
}
|
|
|
|
// 实现Handler的ServerHTTP方法
|
|
func (e *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
switch r.RequestURI {
|
|
case "/":
|
|
fmt.Fprint(w, "hello handler-basic")
|
|
case "/web":
|
|
for k, v := range r.Header {
|
|
fmt.Fprintln(w, k, "-->", v)
|
|
}
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
engine := new(Engine)
|
|
if err := http.ListenAndServe(":9000", engine); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|