25 lines
461 B
Go
25 lines
461 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
func main() {
|
|
// 绑定路由规则,执行的函数
|
|
http.HandleFunc("/", indexHander)
|
|
http.HandleFunc("/hello", helloHandler)
|
|
// 启动服务
|
|
http.ListenAndServe(":8000", nil)
|
|
}
|
|
|
|
func indexHander(w http.ResponseWriter, r *http.Request) {
|
|
fmt.Fprintf(w, "Hello World")
|
|
}
|
|
|
|
func helloHandler(w http.ResponseWriter, r *http.Request) {
|
|
for k, v := range r.Header {
|
|
fmt.Fprintf(w, "Header[%q] = %q", k, v)
|
|
}
|
|
}
|