十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
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