Go实例: HTTP Servers

Diane ·
更新时间:2024-11-13
· 371 次阅读

package main import ( "fmt" "net/http" ) func hello(w http.ResponseWriter, req *http.Request) { fmt.Fprintf(w, "hello\n") } func headers(w http.ResponseWriter, req *http.Request) { for name, headers := range req.Header { for _, h := range headers { fmt.Fprintf(w, "%v: %v\n", name, h) } } } func main() { http.HandleFunc("/hello", hello) http.HandleFunc("/headers", headers) http.ListenAndServe(":8090", nil) }$ go run http-servers.go & Access the /hello route. $ curl localhost:8090/hello hello



GO实例 HTTP GO

需要 登录 后方可回复, 如果你还没有账号请 注册新账号