Skip to content

Commit

Permalink
feat: 删除容器一批无用的接口
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Oct 27, 2024
1 parent 7b53c19 commit 86cec00
Show file tree
Hide file tree
Showing 13 changed files with 0 additions and 287 deletions.
3 changes: 0 additions & 3 deletions internal/biz/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ type ContainerRepo interface {
Restart(id string) error
Pause(id string) error
Unpause(id string) error
Inspect(id string) (types.ContainerJSON, error)
Kill(id string) error
Rename(id string, newName string) error
Stats(id string) (container.StatsResponseReader, error)
Exist(name string) (bool, error)
Update(id string, config container.UpdateConfig) error
Logs(id string) (string, error)
Prune() error
Expand Down
3 changes: 0 additions & 3 deletions internal/biz/container_image.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package biz

import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/image"

"github.com/TheTNB/panel/internal/http/request"
)

type ContainerImageRepo interface {
List() ([]image.Summary, error)
Exist(id string) (bool, error)
Pull(req *request.ContainerImagePull) error
Remove(id string) error
Prune() error
Inspect(id string) (types.ImageInspect, error)
}
4 changes: 0 additions & 4 deletions internal/biz/container_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,5 @@ type ContainerNetworkRepo interface {
List() ([]network.Inspect, error)
Create(req *request.ContainerNetworkCreate) (string, error)
Remove(id string) error
Exist(name string) (bool, error)
Inspect(id string) (network.Inspect, error)
Connect(networkID string, containerID string) error
Disconnect(networkID string, containerID string) error
Prune() error
}
2 changes: 0 additions & 2 deletions internal/biz/container_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
type ContainerVolumeRepo interface {
List() ([]*volume.Volume, error)
Create(req *request.ContainerVolumeCreate) (volume.Volume, error)
Exist(name string) (bool, error)
Inspect(id string) (volume.Volume, error)
Remove(id string) error
Prune() error
}
22 changes: 0 additions & 22 deletions internal/data/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,6 @@ func (r *containerRepo) Unpause(id string) error {
return r.client.ContainerUnpause(context.Background(), id)
}

// Inspect 查看容器
func (r *containerRepo) Inspect(id string) (types.ContainerJSON, error) {
return r.client.ContainerInspect(context.Background(), id)
}

// Kill 杀死容器
func (r *containerRepo) Kill(id string) error {
return r.client.ContainerKill(context.Background(), id, "KILL")
Expand All @@ -185,23 +180,6 @@ func (r *containerRepo) Rename(id string, newName string) error {
return r.client.ContainerRename(context.Background(), id, newName)
}

// Stats 查看容器状态
func (r *containerRepo) Stats(id string) (container.StatsResponseReader, error) {
return r.client.ContainerStats(context.Background(), id, false)
}

// Exist 判断容器是否存在
func (r *containerRepo) Exist(name string) (bool, error) {
var options container.ListOptions
options.Filters = filters.NewArgs(filters.Arg("name", name))
containers, err := r.client.ContainerList(context.Background(), options)
if err != nil {
return false, err
}

return len(containers) > 0, nil
}

// Update 更新容器
func (r *containerRepo) Update(id string, config container.UpdateConfig) error {
_, err := r.client.ContainerUpdate(context.Background(), id, config)
Expand Down
19 changes: 0 additions & 19 deletions internal/data/container_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"io"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/registry"
Expand Down Expand Up @@ -37,18 +36,6 @@ func (r *containerImageRepo) List() ([]image.Summary, error) {
})
}

// Exist 判断镜像是否存在
func (r *containerImageRepo) Exist(id string) (bool, error) {
var options image.ListOptions
options.Filters = filters.NewArgs(filters.Arg("reference", id))
images, err := r.client.ImageList(context.Background(), options)
if err != nil {
return false, err
}

return len(images) > 0, nil
}

// Pull 拉取镜像
func (r *containerImageRepo) Pull(req *request.ContainerImagePull) error {
options := image.PullOptions{}
Expand Down Expand Up @@ -89,9 +76,3 @@ func (r *containerImageRepo) Prune() error {
_, err := r.client.ImagesPrune(context.Background(), filters.NewArgs())
return err
}

// Inspect 查看镜像
func (r *containerImageRepo) Inspect(id string) (types.ImageInspect, error) {
img, _, err := r.client.ImageInspectWithRaw(context.Background(), id)
return img, err
}
17 changes: 0 additions & 17 deletions internal/data/container_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,6 @@ func (r *containerVolumeRepo) Create(req *request.ContainerVolumeCreate) (volume
})
}

// Exist 判断存储卷是否存在
func (r *containerVolumeRepo) Exist(id string) (bool, error) {
var options volume.ListOptions
options.Filters = filters.NewArgs(filters.Arg("name", id))
volumes, err := r.client.VolumeList(context.Background(), options)
if err != nil {
return false, err
}

return len(volumes.Volumes) > 0, nil
}

// Inspect 查看存储卷
func (r *containerVolumeRepo) Inspect(id string) (volume.Volume, error) {
return r.client.VolumeInspect(context.Background(), id)
}

// Remove 删除存储卷
func (r *containerVolumeRepo) Remove(id string) error {
return r.client.VolumeRemove(context.Background(), id, true)
Expand Down
11 changes: 0 additions & 11 deletions internal/route/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,8 @@ func Http(r chi.Router) {
r.Post("/{id}/restart", container.Restart)
r.Post("/{id}/pause", container.Pause)
r.Post("/{id}/unpause", container.Unpause)
r.Get("/{id}/inspect", container.Inspect)
r.Post("/{id}/kill", container.Kill)
r.Post("/{id}/rename", container.Rename)
r.Get("/{id}/stats", container.Stats)
r.Get("/{id}/exist", container.Exist)
r.Get("/{id}/logs", container.Logs)
r.Post("/prune", container.Prune)
})
Expand All @@ -195,28 +192,20 @@ func Http(r chi.Router) {
r.Get("/", containerNetwork.List)
r.Post("/", containerNetwork.Create)
r.Delete("/{id}", containerNetwork.Remove)
r.Get("/{id}/exist", containerNetwork.Exist)
r.Get("/{id}/inspect", containerNetwork.Inspect)
r.Post("/{network}/connect", containerNetwork.Connect)
r.Post("/{network}/disconnect", containerNetwork.Disconnect)
r.Post("/prune", containerNetwork.Prune)
})
r.Route("/image", func(r chi.Router) {
containerImage := service.NewContainerImageService()
r.Get("/", containerImage.List)
r.Get("/{id}/exist", containerImage.Exist)
r.Post("/", containerImage.Pull)
r.Delete("/{id}", containerImage.Remove)
r.Get("/{id}", containerImage.Inspect)
r.Post("/prune", containerImage.Prune)
})
r.Route("/volume", func(r chi.Router) {
containerVolume := service.NewContainerVolumeService()
r.Get("/", containerVolume.List)
r.Post("/", containerVolume.Create)
r.Get("/{id}/exist", containerVolume.Exist)
r.Delete("/{id}", containerVolume.Remove)
r.Get("/{id}", containerVolume.Inspect)
r.Post("/prune", containerVolume.Prune)
})
})
Expand Down
48 changes: 0 additions & 48 deletions internal/service/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,6 @@ func (s *ContainerService) Unpause(w http.ResponseWriter, r *http.Request) {
Success(w, nil)
}

func (s *ContainerService) Inspect(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.ContainerID](r)
if err != nil {
Error(w, http.StatusUnprocessableEntity, "%v", err)
return
}

container, err := s.containerRepo.Inspect(req.ID)
if err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}

Success(w, container)
}

func (s *ContainerService) Kill(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.ContainerID](r)
if err != nil {
Expand Down Expand Up @@ -221,38 +205,6 @@ func (s *ContainerService) Rename(w http.ResponseWriter, r *http.Request) {
Success(w, nil)
}

func (s *ContainerService) Stats(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.ContainerID](r)
if err != nil {
Error(w, http.StatusUnprocessableEntity, "%v", err)
return
}

stats, err := s.containerRepo.Stats(req.ID)
if err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}

Success(w, stats)
}

func (s *ContainerService) Exist(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.ContainerID](r)
if err != nil {
Error(w, http.StatusUnprocessableEntity, "%v", err)
return
}

exist, err := s.containerRepo.Exist(req.ID)
if err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}

Success(w, exist)
}

func (s *ContainerService) Logs(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.ContainerID](r)
if err != nil {
Expand Down
32 changes: 0 additions & 32 deletions internal/service/container_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,6 @@ func (s *ContainerImageService) List(w http.ResponseWriter, r *http.Request) {
})
}

func (s *ContainerImageService) Exist(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.ContainerImageID](r)
if err != nil {
Error(w, http.StatusUnprocessableEntity, "%v", err)
return
}

exist, err := s.containerImageRepo.Exist(req.ID)
if err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}

Success(w, exist)
}

func (s *ContainerImageService) Pull(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.ContainerImagePull](r)
if err != nil {
Expand Down Expand Up @@ -96,22 +80,6 @@ func (s *ContainerImageService) Remove(w http.ResponseWriter, r *http.Request) {
Success(w, nil)
}

func (s *ContainerImageService) Inspect(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.ContainerImageID](r)
if err != nil {
Error(w, http.StatusUnprocessableEntity, "%v", err)
return
}

inspect, err := s.containerImageRepo.Inspect(req.ID)
if err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}

Success(w, inspect)
}

func (s *ContainerImageService) Prune(w http.ResponseWriter, r *http.Request) {
if err := s.containerImageRepo.Prune(); err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
Expand Down
62 changes: 0 additions & 62 deletions internal/service/container_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,68 +98,6 @@ func (s *ContainerNetworkService) Remove(w http.ResponseWriter, r *http.Request)
Success(w, nil)
}

func (s *ContainerNetworkService) Exist(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.ContainerNetworkID](r)
if err != nil {
Error(w, http.StatusUnprocessableEntity, "%v", err)
return
}

exist, err := s.containerNetworkRepo.Exist(req.ID)
if err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}

Success(w, exist)
}

func (s *ContainerNetworkService) Inspect(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.ContainerNetworkID](r)
if err != nil {
Error(w, http.StatusUnprocessableEntity, "%v", err)
return
}

network, err := s.containerNetworkRepo.Inspect(req.ID)
if err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}

Success(w, network)
}

func (s *ContainerNetworkService) Connect(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.ContainerNetworkConnect](r)
if err != nil {
Error(w, http.StatusUnprocessableEntity, "%v", err)
return
}

if err = s.containerNetworkRepo.Connect(req.Network, req.Container); err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}

Success(w, nil)
}

func (s *ContainerNetworkService) Disconnect(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.ContainerNetworkConnect](r)
if err != nil {
Error(w, http.StatusUnprocessableEntity, "%v", err)
return
}

if err = s.containerNetworkRepo.Disconnect(req.Network, req.Container); err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}

Success(w, nil)
}

func (s *ContainerNetworkService) Prune(w http.ResponseWriter, r *http.Request) {
if err := s.containerNetworkRepo.Prune(); err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
Expand Down
Loading

0 comments on commit 86cec00

Please sign in to comment.