package main
import (
"net/http"
"github.com/julienschmidt/httprouter"
"io"
)
//第三個參數(shù)p是httprouter新增的
func CreateUser(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
//io.WriteString(w, "create user")
io.WriteString(w, p.ByName("user_name") + "\n")
//如果沒有的則不會輸出
io.WriteString(w, p.ByName("fffffff") + "\n")
io.WriteString(w, p.ByName(("pwd")) + "\n")
}
//使用httprouter
func RegisterHandlers() *httprouter.Router {
router := httprouter.New()
router.GET("/user/:user_name/pwd/:pwd", CreateUser)
return router
}
func main() {
r := RegisterHandlers()
http.ListenAndServe(":8000", r)
}
輸出:
成都創(chuàng)新互聯(lián)公司-云計(jì)算及IDC服務(wù)提供商,涵蓋公有云、IDC機(jī)房租用、綿陽主機(jī)托管、等保安全、私有云建設(shè)等企業(yè)級互聯(lián)網(wǎng)基礎(chǔ)服務(wù),歡迎咨詢:18982081108