下面的代码在运行 appengine 服务器时提取 url 值,但在测试期间 url var 为空。为什么会这样的任何想法?func init() { s := scheduleApi{} r := NewAERouter() r.HandleFunc("/leagues/{leagueId}/schedule", s.get).Methods("GET") http.Handle("/", r.router)}func (s *scheduleApi) get(c appengine.Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) fmt.Printf("=======================\n") fmt.Printf("URL => %v\n", r.URL) fmt.Printf("params => %v\n", params) // empty map fmt.Printf("leageid => %v\n", params["leagueId"]) // blank fmt.Printf("=======================\n")}测试func Test_Get(t *testing.T) { r, _ := http.NewRequest("GET", "/leagues/99/schedule", nil) w := httptest.NewRecorder() handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { s := scheduleApi{} c, _ := aetest.NewContext(nil) s.get(c, w, r) }) handler.ServeHTTP(w, r) //...}
1 回答
- 1 回答
- 0 关注
- 190 浏览
添加回答
举报
0/150
提交
取消