56 lines
1.0 KiB
Go
56 lines
1.0 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"codespace/internal/model"
|
|
"codespace/internal/service"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type processHandler struct {
|
|
svc *service.ProcessService
|
|
}
|
|
|
|
func (h *processHandler) start(c *gin.Context) {
|
|
id := c.Param("id")
|
|
if err := h.svc.Start(id); err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
c.Status(http.StatusNoContent)
|
|
}
|
|
|
|
func (h *processHandler) stop(c *gin.Context) {
|
|
id := c.Param("id")
|
|
if err := h.svc.Stop(id); err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
c.Status(http.StatusNoContent)
|
|
}
|
|
|
|
func (h *processHandler) restart(c *gin.Context) {
|
|
id := c.Param("id")
|
|
if err := h.svc.Restart(id); err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
c.Status(http.StatusNoContent)
|
|
}
|
|
|
|
func (h *processHandler) status(c *gin.Context) {
|
|
id := c.Param("id")
|
|
status, err := h.svc.Status(id)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, model.ProcessStatusResponse{
|
|
WorkspaceID: status.WorkspaceID,
|
|
Running: status.Running,
|
|
PID: status.PID,
|
|
})
|
|
}
|