getPortPairs parses a list of strings of form "%d:%d" into pairs of (remote, local) numbers.
(ports []string)
| 358 | |
| 359 | // getPortPairs parses a list of strings of form "%d:%d" into pairs of (remote, local) numbers. |
| 360 | func getPortPairs(ports []string) ([]portPair, error) { |
| 361 | pp := make([]portPair, 0, len(ports)) |
| 362 | |
| 363 | for _, portString := range ports { |
| 364 | parts := strings.Split(portString, ":") |
| 365 | if len(parts) < 2 { |
| 366 | return nil, fmt.Errorf("port pair: %q is not valid", portString) |
| 367 | } |
| 368 | |
| 369 | remote, err := strconv.Atoi(parts[0]) |
| 370 | if err != nil { |
| 371 | return pp, fmt.Errorf("convert remote port to int: %w", err) |
| 372 | } |
| 373 | |
| 374 | local, err := strconv.Atoi(parts[1]) |
| 375 | if err != nil { |
| 376 | return pp, fmt.Errorf("convert local port to int: %w", err) |
| 377 | } |
| 378 | |
| 379 | pp = append(pp, portPair{remote, local}) |
| 380 | } |
| 381 | |
| 382 | return pp, nil |
| 383 | } |
| 384 | |
| 385 | func normalizeJSON(j []byte) []byte { |
| 386 | // remove trailing commas |