Group splits a slice of endpoints into groups based on the first hierarchy path. The first hierarchy path will be removed from the result. Input: [ {endpoint0, path: [p0, wt0]} {endpoint1, path: [p0, wt1]} {endpoint2, path: [p1, wt2]} {endpoint3, path: [p1, wt3]} ] Endpoints will be split in
(endpoints []resolver.Endpoint)
| 93 | // If hierarchical path is not set, or has no path in it, the endpoint is |
| 94 | // dropped. |
| 95 | func Group(endpoints []resolver.Endpoint) map[string][]resolver.Endpoint { |
| 96 | ret := make(map[string][]resolver.Endpoint) |
| 97 | for _, endpoint := range endpoints { |
| 98 | oldPath := FromEndpoint(endpoint) |
| 99 | if len(oldPath) == 0 { |
| 100 | continue |
| 101 | } |
| 102 | curPath := oldPath[0] |
| 103 | newPath := oldPath[1:] |
| 104 | newEndpoint := SetInEndpoint(endpoint, newPath) |
| 105 | ret[curPath] = append(ret[curPath], newEndpoint) |
| 106 | } |
| 107 | return ret |
| 108 | } |