第三方路由库httprouter的基本操作
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)
}
输出:
成都创新互联公司-云计算及IDC服务提供商,涵盖公有云、IDC机房租用、绵阳主机托管、等保安全、私有云建设等企业级互联网基础服务,欢迎咨询:18982081108
网页名称:第三方路由库httprouter的基本操作
网页链接:http://ybzwz.com/article/igsjgd.html