【发布时间】:2018-10-05 14:13:15
【问题描述】:
我的删除处理程序:(我正在使用“github.com/gorilla/mux”)
func DeletePerson(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
item := params["id"]
fmt.Println("Item = ", item)
...
当被以下 curl 命令调用时,返回 Item = "2":
curl -X DELETE http://localhost:8000/address/2
但是,我的测试代码:
func TestDeletePerson(t *testing.T) {
person := &Person{
UniqID: "2",
FirstName: "",
LastName: "",
EmailAddr: "",
PhoneNumb: "",
}
jsonPerson, _ := json.Marshal(person)
request, _ := http.NewRequest("DELETE", "/address/2", bytes.NewBuffer(jsonPerson))
response := httptest.NewRecorder()
DeletePerson(response, request)
导致 DeletePerson 返回 "" 和 打印“params”直接返回
map[]
大问题 - 我到底想念什么???
我是否设置了另一个标头参数?
【问题讨论】: