getPortPairs parses a list of strings of form "%d:%d" into pairs of (remote, local) numbers.
(ports []string)
| 370 | |
| 371 | // getPortPairs parses a list of strings of form "%d:%d" into pairs of (remote, local) numbers. |
| 372 | func getPortPairs(ports []string) ([]portPair, error) { |
| 373 | pp := make([]portPair, 0, len(ports)) |
| 374 | |
| 375 | for _, portString := range ports { |
| 376 | parts := strings.Split(portString, ":") |
| 377 | if len(parts) < 2 { |
| 378 | return nil, fmt.Errorf("port pair: %q is not valid", portString) |
| 379 | } |
| 380 | |
| 381 | remote, err := strconv.Atoi(parts[0]) |
| 382 | if err != nil { |
| 383 | return pp, fmt.Errorf("convert remote port to int: %w", err) |
| 384 | } |
| 385 | |
| 386 | local, err := strconv.Atoi(parts[1]) |
| 387 | if err != nil { |
| 388 | return pp, fmt.Errorf("convert local port to int: %w", err) |
| 389 | } |
| 390 | |
| 391 | pp = append(pp, portPair{remote, local}) |
| 392 | } |
| 393 | |
| 394 | return pp, nil |
| 395 | } |
| 396 | |
| 397 | func normalizeJSON(j []byte) []byte { |
| 398 | // remove trailing commas |