From 310316c8e42835a65b96f2e13d3dc44473ea6561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Sun, 27 Oct 2024 17:45:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=AE=B9=E5=99=A8?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/data/container.go | 12 +++++----- internal/http/request/container.go | 36 +++++++++++++++--------------- pkg/types/container.go | 17 +++++--------- 3 files changed, 30 insertions(+), 35 deletions(-) diff --git a/internal/data/container.go b/internal/data/container.go index f792f046..a0776200 100644 --- a/internal/data/container.go +++ b/internal/data/container.go @@ -101,7 +101,7 @@ func (r *containerRepo) Create(req *request.ContainerCreate) (string, error) { sb.WriteString(fmt.Sprintf("%s create --name %s --image %s", r.cmd, req.Name, req.Image)) for _, port := range req.Ports { - sb.WriteString(fmt.Sprintf(" -p %s:%d", port.Host, port.ContainerStart)) + sb.WriteString(fmt.Sprintf(" -p %s:%d-%d:%d-%d/%s", port.Host, port.HostStart, port.HostEnd, port.ContainerStart, port.ContainerEnd, port.Protocol)) } if req.Network != "" { sb.WriteString(fmt.Sprintf(" --network %s", req.Network)) @@ -248,10 +248,12 @@ func (r *containerRepo) parsePorts(ports string) []types.ContainerPort { protocol := matches[4] portList = append(portList, types.ContainerPort{ - IP: host, - PublicPort: cast.ToUint(public), - PrivatePort: cast.ToUint(private), - Type: protocol, + Host: host, + HostStart: cast.ToUint(public), + HostEnd: cast.ToUint(public), + ContainerStart: cast.ToUint(private), + ContainerEnd: cast.ToUint(private), + Protocol: protocol, }) } diff --git a/internal/http/request/container.go b/internal/http/request/container.go index b34b7157..db17ede3 100644 --- a/internal/http/request/container.go +++ b/internal/http/request/container.go @@ -12,22 +12,22 @@ type ContainerRename struct { } type ContainerCreate struct { - Name string `form:"name" json:"name" validate:"required"` - Image string `form:"image" json:"image" validate:"required"` - Ports []types.ContainerCreatePort `form:"ports" json:"ports"` - Network string `form:"network" json:"network"` - Volumes []types.ContainerVolume `form:"volumes" json:"volumes"` - Labels []types.KV `form:"labels" json:"labels"` - Env []types.KV `form:"env" json:"env"` - Entrypoint []string `form:"entrypoint" json:"entrypoint"` - Command []string `form:"command" json:"command"` - RestartPolicy string `form:"restart_policy" json:"restart_policy"` - AutoRemove bool `form:"auto_remove" json:"auto_remove"` - Privileged bool `form:"privileged" json:"privileged"` - OpenStdin bool `form:"openStdin" json:"open_stdin"` - PublishAllPorts bool `form:"publish_all_ports" json:"publish_all_ports"` - Tty bool `form:"tty" json:"tty"` - CPUShares int64 `form:"cpu_shares" json:"cpu_shares"` - CPUs int64 `form:"cpus" json:"cpus"` - Memory int64 `form:"memory" json:"memory"` + Name string `form:"name" json:"name" validate:"required"` + Image string `form:"image" json:"image" validate:"required"` + Ports []types.ContainerPort `form:"ports" json:"ports"` + Network string `form:"network" json:"network"` + Volumes []types.ContainerVolume `form:"volumes" json:"volumes"` + Labels []types.KV `form:"labels" json:"labels"` + Env []types.KV `form:"env" json:"env"` + Entrypoint []string `form:"entrypoint" json:"entrypoint"` + Command []string `form:"command" json:"command"` + RestartPolicy string `form:"restart_policy" json:"restart_policy"` + AutoRemove bool `form:"auto_remove" json:"auto_remove"` + Privileged bool `form:"privileged" json:"privileged"` + OpenStdin bool `form:"openStdin" json:"open_stdin"` + PublishAllPorts bool `form:"publish_all_ports" json:"publish_all_ports"` + Tty bool `form:"tty" json:"tty"` + CPUShares int64 `form:"cpu_shares" json:"cpu_shares"` + CPUs int64 `form:"cpus" json:"cpus"` + Memory int64 `form:"memory" json:"memory"` } diff --git a/pkg/types/container.go b/pkg/types/container.go index 76937e35..c2a6430a 100644 --- a/pkg/types/container.go +++ b/pkg/types/container.go @@ -2,13 +2,6 @@ package types import "time" -type ContainerPort struct { - IP string `json:"ip,omitempty"` - PrivatePort uint `json:"private_port"` - PublicPort uint `json:"public_port,omitempty"` - Type string `json:"type"` -} - type Container struct { ID string `json:"id"` Name string `json:"name"` @@ -22,12 +15,12 @@ type Container struct { Status string } -type ContainerCreatePort struct { - ContainerStart int `form:"container_start" json:"container_start"` - ContainerEnd int `form:"container_end" json:"container_end"` +type ContainerPort struct { + ContainerStart uint `form:"container_start" json:"container_start"` + ContainerEnd uint `form:"container_end" json:"container_end"` Host string `form:"host" json:"host"` - HostStart int `form:"host_start" json:"host_start"` - HostEnd int `form:"host_end" json:"host_end"` + HostStart uint `form:"host_start" json:"host_start"` + HostEnd uint `form:"host_end" json:"host_end"` Protocol string `form:"protocol" json:"protocol"` }