昂首阔步的参数问题

下面是我的代码:


// 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 userParam

type UserRequest struct {

    // aaaa

    // in: query

    UserId string `json:"user_id"`

}

生成不可靠的json时出现错误。


panic: assignment to entry in nil map


goroutine 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 +0x635

github.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 her


parameters:

        - name: user_id

          in: query

          description: this argument is a string

          schema:

            type: string


aluckdog
浏览 287回答 1
1回答

慕码人2483693

您的示例不完整。但是,使用您已有的代码,您的代码应该看起来像最简单的形式:// swagger:parameters GetUsertype GetUser struct {    // UserId that identifies a user.    //    // in: query    UserId string `json:"user_id"`}// Returns a user.// swagger:response UserResponsetype UserResponse struct {     // in: body    Body struct {}}// swagger:route GET /user_list GetUser//// Get a user profile.//// Responses://      200: UserResponserouter.Get("/user_list", handler.GetUser)注意我们有三件事:请求对象响应对象同时使用请求和响应对象的路由
打开App,查看更多内容
随时随地看视频慕课网APP