(ctx *gin.Context)
| 412 | } |
| 413 | |
| 414 | func (i *imlServiceController) ExportSwagger(ctx *gin.Context) { |
| 415 | id, has := ctx.Params.Get("id") |
| 416 | if !has { |
| 417 | ctx.JSON(200, &pm3.Response{ |
| 418 | Code: -1, |
| 419 | Success: "fail", |
| 420 | Message: fmt.Sprintf("id is required"), |
| 421 | }) |
| 422 | return |
| 423 | } |
| 424 | s, err := i.module.Get(ctx, id) |
| 425 | if err != nil { |
| 426 | ctx.JSON(200, &pm3.Response{ |
| 427 | Code: -1, |
| 428 | Success: "fail", |
| 429 | Message: err.Error(), |
| 430 | }) |
| 431 | return |
| 432 | } |
| 433 | tmp, err := i.swagger(ctx, id) |
| 434 | if err != nil { |
| 435 | ctx.JSON(200, &pm3.Response{ |
| 436 | Code: -1, |
| 437 | Success: "fail", |
| 438 | Message: err.Error(), |
| 439 | }) |
| 440 | return |
| 441 | } |
| 442 | |
| 443 | data, _ := tmp.MarshalJSON() |
| 444 | ctx.Status(200) |
| 445 | // 设置响应头 |
| 446 | ctx.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s.json", strings.Replace(s.Name, " ", "_", -1))) |
| 447 | ctx.Header("Content-Type", "application/octet-stream") |
| 448 | ctx.Header("Content-Transfer-Encoding", "binary") |
| 449 | ctx.Writer.Write(data) |
| 450 | return |
| 451 | } |
| 452 | |
| 453 | func (i *imlServiceController) Swagger(ctx *gin.Context) { |
| 454 | id, has := ctx.Params.Get("id") |
nothing calls this directly
no test coverage detected