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