标题: go学习:启动http服务
时间: 2021-08-25
package main
import (
"log"
"net/http"
)
// IndexHandler 首页路由处理函数
func IndexHandler(w http.ResponseWriter, req *http.Request) {
// 响应 hello world
_, err := w.Write([]byte("hello world"))
if err != nil {
log.Fatalln("listen err:", err)
}
}
func main() {
// 注册首页路由的处理函数
http.HandleFunc("/", IndexHandler)
// 监听端口启动服务
err := http.ListenAndServe(":8089", nil)
if err != nil {
log.Fatalln("listen err:", err)
}
}
『回复列表(8|隐藏机器人聊天)』