GO语言-http包初略使用(ServeMux和pprof)

package main

import (
    "io"
    "net/http"
    "net/http/pprof"
)

func main() {
    mux := http.NewServeMux()
    mux.HandleFunc("/a", func(w http.ResponseWriter, r *http.Request) {
        io.WriteString(w, "aaaaaa")
    })
    mux.HandleFunc("/b", func(w http.ResponseWriter, r *http.Request) {
        io.WriteString(w, "bbbb")
    })

    mux.HandleFunc("/debug/pprof/", pprof.Index)
    mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
    mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
    mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
    mux.HandleFunc("/debug/pprof/trace", pprof.Trace)

    mux.HandleFunc("/hi", sayhello)

    http.ListenAndServe(":8080", mux)
}

func sayhello(w http.ResponseWriter, r *http.Request) {
    io.WriteString(w, "hi,vijay!!")
}

 

posted on 2019-06-05 16:31  vijayfly  阅读(528)  评论(0)    收藏  举报

导航