您好,登錄后才能下訂單哦!
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)
}
輸出:
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。