为了账号安全,请及时绑定邮箱和手机立即绑定

昂首阔步的参数问题

昂首阔步的参数问题

Go
aluckdog 2021-04-02 14:22:54
下面是我的代码:// swagger:route GET /user_list get_user//// Get a user profile// Parameters://  user_id: userParam// Consumes:// - application/json// Produces:// - application/json//// Responses://      200: UserResponse在我的请求模型中,我添加了如下参数:// swagger:parameters userParamtype UserRequest struct {    // aaaa    // in: query    UserId string `json:"user_id"`}生成不可靠的json时出现错误。panic: assignment to entry in nil mapgoroutine 1 [running]:github.com/go-swagger/go-swagger/scan.(*setOpParams).Parse(0xc428986a20, 0xc426439f30, 0x1, 0x1, 0x0, 0x0)    /home/sotsys-056/go_10/src/github.com/go-swagger/go-swagger/scan/route_params.go:137 +0x635github.com/go-swagger/go-swagger/scan.(*tagParser).Parse(0xc426e873d0, 0xc426439f30, 0x1, 0x1, 0x0, 0xc426439f30)    /home/sotsys-056/go_10/src/github.com/go-swagger/go-swagger/scan/scanner.go:526 +0x52当我删除参数部分时,它工作正常,我不会生成swagger json,但是带有参数我无法生成它。我也尝试过这些方法。// Parameters://      - user_id: [in:query required:true type:string] Description goes herparameters:        - name: user_id          in: query          description: this argument is a string          schema:            type: string
查看完整描述

1 回答

?
慕码人2483693

TA贡献1860条经验 获得超9个赞

您的示例不完整。但是,使用您已有的代码,您的代码应该看起来像最简单的形式:


// swagger:parameters GetUser

type GetUser struct {

    // UserId that identifies a user.

    //

    // in: query

    UserId string `json:"user_id"`

}


// Returns a user.

// swagger:response UserResponse

type UserResponse struct { 

    // in: body

    Body struct {}

}


// swagger:route GET /user_list GetUser

//

// Get a user profile.

//

// Responses:

//      200: UserResponse

router.Get("/user_list", handler.GetUser)

注意我们有三件事:


请求对象

响应对象

同时使用请求和响应对象的路由


查看完整回答
反对 回复 2021-04-19
  • 1 回答
  • 0 关注
  • 285 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信