@@ -2,16 +2,15 @@ package autoconf
22
33import (
44 "math/rand"
5+ "slices"
56 "strings"
67)
78
89// normalizeURLs ensures all URLs in the slice have no trailing slashes
9- func normalizeURLs (urls []string ) []string {
10- normalized := make ([]string , len (urls ))
10+ func normalizeURLs (urls []string ) {
1111 for i , url := range urls {
12- normalized [i ] = strings .TrimRight (url , "/" )
12+ urls [i ] = strings .TrimRight (url , "/" )
1313 }
14- return normalized
1514}
1615
1716// expandAutoConfSlice is a generic helper for expanding "auto" placeholders in string slices.
@@ -163,33 +162,30 @@ func ExpandDelegatedEndpoints(configEndpoints []string, autoConf *Config, native
163162 return result
164163 }
165164
166- var routers []string
167165 seen := make (map [string ]struct {})
168-
169166 for baseURL , config := range endpoints {
170167 // Combine both Read and Write paths (already filtered by WithSupportedPathsOnly)
171- allPaths := append (config .Read , config .Write ... )
172-
168+ uniquePaths := slices .Concat (config .Read , config .Write )
173169 // Deduplicate paths (in case same path appears in both Read and Write)
174- uniquePaths := make (map [string ]struct {}, len (allPaths ))
175- for _ , path := range allPaths {
176- uniquePaths [path ] = struct {}{}
177- }
170+ slices .Sort (uniquePaths )
171+ uniquePaths = slices .Compact (uniquePaths )
178172
179- for path := range uniquePaths {
173+ for _ , path := range uniquePaths {
180174 url := buildEndpointURL (baseURL , path )
181- if _ , exists := seen [url ]; ! exists {
182- routers = append (routers , url )
183- seen [url ] = struct {}{}
184- }
175+ seen [url ] = struct {}{}
185176 }
186177 }
187178
179+ routers := make ([]string , 0 , len (seen ))
180+ for url := range seen {
181+ routers = append (routers , url )
182+ }
183+
188184 resolved := expandAutoConfSlice (configEndpoints , routers )
189185
190186 // Normalize all URLs to ensure no trailing slashes
191187 // (autoconf URLs are already normalized, but user-provided custom URLs might not be)
192- resolved = normalizeURLs (resolved )
188+ normalizeURLs (resolved )
193189
194190 log .Debugf ("ExpandDelegatedEndpoints: final result contains %d endpoints" , len (resolved ))
195191 return resolved
0 commit comments