fix: 解决容器端口解析失败的问题 (#2739)

This commit is contained in:
ssongliu 2023-10-31 18:03:51 +08:00 committed by GitHub
parent bc80dfdc68
commit ded99190c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1019,28 +1019,29 @@ func simplifyPort(ports []types.Port) []string {
if start.PublicPort != 0 {
itemPortStr = fmt.Sprintf("%s:%v->%v/%s", start.IP, start.PublicPort, start.PrivatePort, start.Type)
}
datas = append(datas, itemPortStr)
datas = append(datas, strings.TrimPrefix(itemPortStr, ":"))
} else {
itemPortStr := fmt.Sprintf("%s:%v-%v/%s", start.IP, start.PrivatePort, ports[i-1].PrivatePort, start.Type)
if start.PublicPort != 0 {
itemPortStr = fmt.Sprintf("%s:%v-%v->%v-%v/%s", start.IP, start.PublicPort, ports[i-1].PublicPort, start.PrivatePort, ports[i-1].PrivatePort, start.Type)
}
datas = append(datas, itemPortStr)
datas = append(datas, strings.TrimPrefix(itemPortStr, ":"))
}
start = ports[i]
} else if i == len(ports)-1 {
}
if i == len(ports)-1 {
if ports[i].PrivatePort == start.PrivatePort {
itemPortStr := fmt.Sprintf("%s:%v/%s", start.IP, start.PrivatePort, start.Type)
if start.PublicPort != 0 {
itemPortStr = fmt.Sprintf("%s:%v->%v/%s", start.IP, start.PublicPort, start.PrivatePort, start.Type)
}
datas = append(datas, itemPortStr)
datas = append(datas, strings.TrimPrefix(itemPortStr, ":"))
} else {
itemPortStr := fmt.Sprintf("%s:%v-%v/%s", start.IP, start.PrivatePort, ports[i].PrivatePort, start.Type)
if start.PublicPort != 0 {
itemPortStr = fmt.Sprintf("%s:%v-%v->%v-%v/%s", start.IP, start.PublicPort, ports[i].PublicPort, start.PrivatePort, ports[i].PrivatePort, start.Type)
}
datas = append(datas, itemPortStr)
datas = append(datas, strings.TrimPrefix(itemPortStr, ":"))
}
}
}