code: func processPorts(app marathon.Application, task marathon.Task, serverPort string) (int, error) {
  	if len(serverPort) > 0 && !strings.HasPrefix(serverPort, "index:") {
  		port, err := strconv.Atoi(serverPort)
  		if err != nil {
  			return 0, err
  		}
  
  		if port <= 0 {
  			return 0, fmt.Errorf("explicitly specified port %d must be greater than zero", port)
  		} else if port > 0 {
  			return port, nil
  		}
  	}
  
  	ports := retrieveAvailablePorts(app, task)
  	if len(ports) == 0 {
  		return 0, errors.New("no port found")
  	}
  
  	portIndex := 0
  	if strings.HasPrefix(serverPort, "index:") {
  		split := strings.SplitN(serverPort, ":", 2)
  		index, err := strconv.Atoi(split[1])
  		if err != nil {
  			return 0, err
  		}
  
  		if index < 0 || index > len(ports)-1 {
  			return 0, fmt.Errorf("index %d must be within range (0, %d)", index, len(ports)-1)
  		}
  		portIndex = index
  	}
  	return ports[portIndex], nil
  }
docs: // processPorts returns the configured port.
  // An explicitly specified port is preferred. If none is specified, it selects
  // one of the available port. The first such found port is returned unless an
  // optional index is provided.