package main
import (
"net/http"
"github.com/julienschmidt/httprouter"
"io"
)
//第三个参数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)
}
输出: