V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
Goat121
V2EX  ›  Go 编程语言

有用过 go-swagger 的大佬么 请教几个问题

  •  
  •   Goat121 · 2021-01-19 12:57:42 +08:00 · 1626 次点击
    这是一个创建于 1190 天前的主题,其中的信息可能已经有所发展或是发生改变。

    1. 我在服务器上用 swagger serve 把服务启在 7500 端口,点测试的时候也访问了 7500,但是我要测试的业务启在 7501,怎么解决这个啊

    2. 我按如下格式定义了一个 GET 请求的 form 参数,无法正确显示。这种该怎么定义呢?

    // swagger:parameters download
    type download struct {
    	// in: path
    	resource.DownloadIn
    }
    
    type DownloadIn struct {
    	ResourceId string `form:"resourceId" binding:"required"`
    }
    

    3. 返回参数按如下定义,能正常显示但是 code 值一直是 0,我想显示为 200,有办法么?

    // Success response
    // swagger:response downloadWrapper
    type downloadWrapper struct {
    	// in: body
    	Body struct {
    		Code int                `json:"code"`
    		Msg  resource.UploadOut `json:"msg"`
    	}
    }
    

    多谢指教🙏🙏🙏

    4 条回复    2021-01-22 20:21:40 +08:00
    pwli
        1
    pwli  
       2021-01-19 16:32:26 +08:00   ❤️ 1
    1. nginx 转发下?|| 自己渲染 swagger
    2. // in: path 代表路由参数,貌似不能是复合结构
    3. // example: 200
    jindeq
        2
    jindeq  
       2021-01-19 16:48:30 +08:00
    没看懂
    Goat121
        3
    Goat121  
    OP
       2021-01-19 21:25:25 +08:00
    @pwli 非常感谢大佬!都解决啦
    Goat121
        4
    Goat121  
    OP
       2021-01-22 20:21:40 +08:00
    @pwli 大佬,再请教一下,我定义了
    ```
    // securityDefinitions:
    // Bearer:
    // type: apiKey
    // name: Authorization
    // in: header
    //
    ```
    然后在需要鉴权的接口定义了
    ```
    // security:
    // - Bearer: []
    ```
    但是现在不知道怎样在 swagger-ui 调用 login 登陆后,把 token 给其他接口使用,类似 postman 的效果
    请问这个要怎么弄
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3380 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 12:10 · PVG 20:10 · LAX 05:10 · JFK 08:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.