Go Gorilla mux处理API请求

我想从下面的gorilla mux router input.package main获取映射结构
例如,

 router.Methods("GET").Path("/api/{action}").HandlerFunc(httpLog(myHandler))

func myHandler(rw http.ResponseWriter, r *http.Request) {
    vars := mux.Vars(r)
    log.Println(vars["action"])
}

服务0.0.0.0:3000/api/input并打印出字符串input
如果我希望能够收到如下请求:
0.0.0.0:3000/api/v3?id=hello&password=great&product=ipad&confirm=true
根据这些要求,我想得到一张地图:
map["id"] = "hello"
map["password"] = "great"
map["product"] = "ipad"
map["confirm"] = "true"


最佳答案:

你要我做吗?

func myHandler(r http.ResponseWriter, q *http.Request) {
    vars := mux.Vars(q)
    fmt.Println(vars["action"])

    fmt.Println(q.FormValue("id"))
    fmt.Println(q.FormValue("password"))
    fmt.Println(q.FormValue("product")) 
    fmt.Println(q.FormValue("confirm"))     
}