惊风破浪的博客
PHP
MySQL
Redis
Linux
算法与设计模式
杂项
Golang
登录
Go的Http服务器和Http客户端
1个月前 ⋅
0
#### http服务器 ```go 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) { //handle for name,headers:=range req.Header{ for _,h :=range headers{ fmt.Fprintf(w, "%v: %v\n", name, h) } } } func main() { // 使用 `http.HandleFunc` 函数,可以方便的将我们的 handler 注册到服务器路由。 // 它是 `net/http` 包中的默认路由,接受一个函数作为参数。 http.HandleFunc("/hello", hello) http.HandleFunc("/headers", headers) // 最后,我们用端口和处理程序调用 `ListenAndServe`。`nil` 告诉它使用我们刚刚设置的默认路由器。 http.ListenAndServe(":8090", nil) } ``` #### http客户端
回复
发布文章
友情链接
Mr.Zhu
Swoole
PHP官网
菜鸟教程
Go语言中文网
implode
数据结构与算法