encodePlatforms marshals the given platform(s) to JSON format, to be used for query-parameters for filtering / selecting platforms.
(platform ...ocispec.Platform)
| 77 | // encodePlatforms marshals the given platform(s) to JSON format, to |
| 78 | // be used for query-parameters for filtering / selecting platforms. |
| 79 | func encodePlatforms(platform ...ocispec.Platform) ([]string, error) { |
| 80 | if len(platform) == 0 { |
| 81 | return []string{}, nil |
| 82 | } |
| 83 | if len(platform) == 1 { |
| 84 | p, err := encodePlatform(&platform[0]) |
| 85 | if err != nil { |
| 86 | return nil, err |
| 87 | } |
| 88 | return []string{p}, nil |
| 89 | } |
| 90 | |
| 91 | seen := make(map[string]struct{}, len(platform)) |
| 92 | out := make([]string, 0, len(platform)) |
| 93 | for i := range platform { |
| 94 | p, err := encodePlatform(&platform[i]) |
| 95 | if err != nil { |
| 96 | return nil, err |
| 97 | } |
| 98 | if _, ok := seen[p]; !ok { |
| 99 | out = append(out, p) |
| 100 | seen[p] = struct{}{} |
| 101 | } |
| 102 | } |
| 103 | return out, nil |
| 104 | } |
| 105 | |
| 106 | // encodePlatform marshals the given platform to JSON format, to |
| 107 | // be used for query-parameters for filtering / selecting platforms. It |
searching dependent graphs…