(http *gin.Context)
| 333 | } |
| 334 | |
| 335 | func (self Compose) ContainerCtrl(http *gin.Context) { |
| 336 | type ParamsValidate struct { |
| 337 | Id string `json:"id" binding:"required"` |
| 338 | Op string `json:"op" binding:"required" oneof:"start restart stop pause unpause ls"` |
| 339 | } |
| 340 | params := ParamsValidate{} |
| 341 | if !self.Validate(http, ¶ms) { |
| 342 | return |
| 343 | } |
| 344 | composeRow, _ := logic.Compose{}.Get(params.Id) |
| 345 | if composeRow == nil { |
| 346 | self.JsonResponseWithError(http, function.ErrorMessage(define.ErrorMessageCommonDataNotFoundOrDeleted), 500) |
| 347 | return |
| 348 | } |
| 349 | tasker, _, err := logic.Compose{}.GetTasker(composeRow) |
| 350 | if err != nil { |
| 351 | self.JsonResponseWithError(http, err, 500) |
| 352 | return |
| 353 | } |
| 354 | |
| 355 | progress := ws.NewProgressPip(fmt.Sprintf(ws.MessageTypeCompose, params.Id)) |
| 356 | defer progress.Close() |
| 357 | |
| 358 | response, err := tasker.Ctrl(params.Op) |
| 359 | if err != nil { |
| 360 | self.JsonResponseWithError(http, err, 500) |
| 361 | return |
| 362 | } |
| 363 | go func() { |
| 364 | <-progress.Done() |
| 365 | _ = response.Close() |
| 366 | }() |
| 367 | _, err = io.Copy(progress, response) |
| 368 | if err != nil { |
| 369 | slog.Warn("compose destroy copy", "error", err) |
| 370 | } |
| 371 | |
| 372 | self.JsonSuccessResponse(http) |
| 373 | return |
| 374 | } |
| 375 | |
| 376 | func (self Compose) ContainerLog(http *gin.Context) { |
| 377 | type ParamsValidate struct { |
nothing calls this directly
no test coverage detected