Initial commit
This commit is contained in:
42
internal/podman/podman_controller.go
Normal file
42
internal/podman/podman_controller.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package podman
|
||||
|
||||
import (
|
||||
"git.cesium.pw/niku/virteen/internal/podman/models"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type PodmanController struct {
|
||||
containerService *models.PodmanService
|
||||
}
|
||||
|
||||
func NewPodmanController(cs *models.PodmanService) *PodmanController {
|
||||
return &PodmanController{containerService: cs}
|
||||
}
|
||||
|
||||
func (cc *PodmanController) ListContainers(ctx *fiber.Ctx) error {
|
||||
containerList, err := (*cc.containerService).List()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return ctx.JSON(containerList)
|
||||
}
|
||||
|
||||
func (cc *PodmanController) CreateContainer(ctx *fiber.Ctx) error {
|
||||
var blueprint models.ContainerBlueprint
|
||||
if err := ctx.BodyParser(&blueprint); err != nil {
|
||||
return err
|
||||
}
|
||||
return (*cc.containerService).Create(blueprint)
|
||||
}
|
||||
|
||||
func (cc *PodmanController) UpdateContainerStatus(ctx *fiber.Ctx) error {
|
||||
name := ctx.Params("name")
|
||||
state := ctx.Query("state")
|
||||
return (*cc.containerService).UpdateStatus(name, state)
|
||||
}
|
||||
|
||||
func (cc *PodmanController) DeleteContainer(ctx *fiber.Ctx) error {
|
||||
name := ctx.Params("name")
|
||||
return (*cc.containerService).Delete(name)
|
||||
}
|
||||
Reference in New Issue
Block a user