1
我在這種方法做錯了什麼?在招搖的工作POST的示例代碼去
我嘗試重新實現一箇舊的API,但是執行。基本上我嘗試發送一個字符串列表到服務器。但我得到的是來自服務器的錯誤500,whenn我嘗試:
go run gen/cmd/greeter-server/main.go --port=3000 &
echo '["a","b"]' | http -v post :34307/api/greeting/2.0/revisit
結果
HTTP/1.1 500 Internal Server Error
Content-Length: 68
Content-Type: application/json
Date: Mon, 06 Mar 2017 17:41:16 GMT
{
"code": 500,
"message": "no consumer registered for application/json"
}
這是代碼中,我試圖實現。
api.TrackingRevisitHandler = operations.TrackingRevisitHandlerFunc(
func(params operations.TrackingRevisitParams) middleware.Responder {
list := params.IdList
log.Printf("%v\n",list)
return operations.NewTrackingRevisitOK().WithPayload("RESULT")
})
我用
swagger generate server -A greeter -t gen -f ./swagger/swagger.yml
產生從這個YAML服務器:
---
swagger: '2.0'
info:
version: 1.0.0
title: Greeting Server
basePath: "/api/greeting/2.0"
paths:
/revisit:
post:
produces:
- application/json
consumes:
- application/json
parameters:
- name: site
required: true
type: string
in: query
description: site name
- name: userlist
in: body
description: list of users
required: true
schema:
"$ref": "#/definitions/Userlist"
operationId: trackingRevisit
responses:
200:
description: return list of users which need revisit
schema:
type: string