本文作者:温文曦

最简单go语言http演示

温文曦 2022-03-11 362 抢沙发
最简单go语言http演示摘要:         最近迷恋go语言,想了解一下go语言写网站,然后找了个简单例子,记着,以后用pack...

        最近迷恋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, "文曦博客\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("/", wenxi)
    http.HandleFunc("/hello", hello)
    http.HandleFunc("/headers", headers)
    http.ListenAndServe(":8090", nil)
}


文章版权及转载声明

作者:温文曦本文地址:https://www.wxnotes.com/blog/685.html发布于 2022-03-11
文章转载或复制请以超链接形式并注明出处文曦博客

赞(3)
阅读
分享

发表评论

快捷回复:

评论列表 (暂无评论,362人围观)参与讨论

还没有评论,来说两句吧...