最简单go语言http演示

        最近迷恋go语言,想了解一下go语言写网站,然后找了个简单例子,记着,以后用

package main
import (
    "fmt"
    "net/http"
)
func wenxi(w http.ResponseWriter, req *http.Request) {
    fmt.Fprintf(w, "路由:nheloo:/hello nheaders:/headers")
}
func hello(w http.ResponseWriter, req *http.Request) {
    fmt.Fprintf(w, "kekc博客/n")
}
func headers(w http.ResponseWriter, req *http.Request) {
    for name, headers := range req.Header {
        for _, h := range headers {
            fmt.Fprintf(w, "%v: %vn", name, h)
        }
    }
}
func main() {
    http.HandleFunc("/", wenxi)
    http.HandleFunc("/hello", hello)
    http.HandleFunc("/headers", headers)
    http.ListenAndServe(":8090", nil)
}
© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容