ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] > [參考](https://goswagger.io/use/spec/route.html) ## router 语法 ``` swagger:route [method] [path pattern] [?tag1 tag2 tag3] [operation id] ``` | Annotation | Format | | --- | --- | | **Consumes** | a list of operation specific mime type values, one per line, for the content the API receives | | **Produces** | a list of operation specific mime type values, one per line, for the content the API sends | | **Schemes** | a list of operation specific schemes the API accept (possible values: http, https, ws, wss) https is preferred as default when configured | | **Deprecated** | Route marked as deprecated if this value is true | | **Security** | a dictionary of key: \[\]string{scopes} | | **Parameters** | a list of parameters that this API accepts | | **Responses** | a dictionary of status code to named response | 在route 中设置 参数的方式有两种,一个是在 route 中填写 Parameters,另一个绑定另一个 声明为`Parameters` 的结构体 code ``` // swagger:route GET /users/{id} users1 getSingleUser // // get a user by userID // // This will show a user info // // Consumes: // - application/json // - application/x-protobuf // // Produces: // - application/json // - application/x-protobuf // // Parameters: // + name: limit // in: query // description: maximum numnber of results to return // required: false // type: integer // format: int32 // // Security: // api_key: // oauth: read, write // // Responses: // 200: swaggScsResp func Chat(c *gin.Context) { ``` code 中的 `getSingleUser ` 需要与 parameters 的名称绑定 如 ``` // swagger:parameters getSingleUser type chatParam struct { // an id of user info // // Required: true // unique: true // in: path // Example:"asdsad" Q string `form:"q" example:"a"` // aaaaaaaaaaa // // Required: true // in: Query A string `form:"11" exmaple:"aaa"` } ``` `swagger:parameters getSingleUser` 中 `getSingleUser` 表示对这个元素的名称 **result** ``` --- paths: /users/{id}: get: consumes: - application/json - application/x-protobuf description: This will show a user info operationId: getSingleUser parameters: - description: an id of user info in: path name: Q required: true type: string - description: aaaaaaaaaaa in: query name: A required: true type: string - description: maximum numnber of results to return format: int32 in: query name: limit type: integer produces: - application/json - application/x-protobuf responses: "200": $ref: '#/responses/swaggScsResp' security: - api_key: [] - oauth: - read - write summary: get a user by userID tags: - users1 ```