Explorar o código

prevent panic if you use API in a wrong way

Victor Vieux %!s(int64=11) %!d(string=hai) anos
pai
achega
49d7b87cfc
Modificáronse 1 ficheiros con 5 adicións e 1 borrados
  1. 5 1
      container.go

+ 5 - 1
container.go

@@ -133,7 +133,11 @@ type PortBinding struct {
 type Port string
 type Port string
 
 
 func (p Port) Proto() string {
 func (p Port) Proto() string {
-	return strings.Split(string(p), "/")[1]
+	parts := strings.Split(string(p), "/")
+	if len(parts) == 1 {
+		return "tcp"
+	}
+	return parts[1]
 }
 }
 
 
 func (p Port) Port() string {
 func (p Port) Port() string {