2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 07:57:21 +08:00

feat: 优化容器结构体

This commit is contained in:
耗子
2024-10-27 17:45:36 +08:00
parent 7521b0f788
commit 310316c8e4
3 changed files with 30 additions and 35 deletions

View File

@@ -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,
})
}

View File

@@ -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"`
}

View File

@@ -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"`
}