Tôi đang chạy trên HTTPS (cảng 10.443) và sử dụng subroutes:mux.Vars không làm việc
mainRoute := mux.NewRouter()
mainRoute.StrictSlash(true)
mainRoute.Handle("/", http.RedirectHandler("/static/", 302))
mainRoute.PathPrefix("/static/").Handler(http.StripPrefix("/static", *fh))
// Bind API Routes
apiRoute := mainRoute.PathPrefix("/api").Subrouter()
apiProductRoute := apiRoute.PathPrefix("/products").Subrouter()
apiProductRoute.Handle("/", handler(listProducts)).Methods("GET")
Và các chức năng:
func listProducts(w http.ResponseWriter, r *http.Request) (interface{}, *handleHTTPError) {
vars := mux.Vars(r)
productType, ok := vars["id"]
log.Println(productType)
log.Println(ok)
}
ok
là false
và tôi không có ý tưởng tại sao. Tôi đang thực hiện một đơn giản ?type=model
sau URL của mình ..
Tất nhiên haha, tệ của tôi. Làm cho cảm giác bây giờ^_^ –
Điều gì về các tham số truy vấn? @elithrar – kamal
@kamal "Chuỗi truy vấn trong phần Truy cập được truy cập qua r.URL.Query" – elithrar