7Days/day1/base3/main.go

32 lines
708 B
Go

package main
import (
"fmt"
"gee"
"net/http"
)
func main() {
// 创建 Engine 实例
r := gee.New()
// 增加一个 GET 路由, path 为 /
r.GET("/", func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("Hello World"))
})
// 增加一个 GET 路由, path 为 /hello
r.GET("/hello", func(w http.ResponseWriter, r *http.Request) {
for k, v := range r.Header {
_, _ = fmt.Fprintf(w, "Header[%q] = %q", k, v)
}
})
// 增加一个 POST 路由, path 为 /login
r.POST("/login", func(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprintf(w, "POST login")
})
// 创建服务端口的监听并开启 Http 服务
err := r.Run(":8000")
if err != nil {
return
}
}