File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change 19
19
package resolver
20
20
21
21
import (
22
- "encoding/json "
22
+ "encoding/base64 "
23
23
"sort"
24
+ "strings"
24
25
)
25
26
26
27
type addressMapEntry struct {
@@ -184,17 +185,19 @@ func NewEndpointMap() *EndpointMap {
184
185
}
185
186
}
186
187
188
+ // encodeEndpoint returns a string that uniquely identifies the unordered set of
189
+ // addresses within an endpoint.
187
190
func encodeEndpoint (e Endpoint ) endpointMapKey {
188
191
addrs := make ([]string , 0 , len (e .Addresses ))
192
+ // base64 encoding the address strings restricts the characters present
193
+ // within the strings. This allows us to use a delimiter without the need of
194
+ // escape characters.
189
195
for _ , addr := range e .Addresses {
190
- addrs = append (addrs , addr .String ())
196
+ addrs = append (addrs , base64 . StdEncoding . EncodeToString ([] byte ( addr .String ()) ))
191
197
}
192
198
sort .Strings (addrs )
193
- encoded , err := json .Marshal (addrs )
194
- if err != nil {
195
- panic ("Failed to marshal []string to JSON: " + err .Error ())
196
- }
197
- return endpointMapKey (encoded )
199
+ // " " should not appear in base64 encoded strings.
200
+ return endpointMapKey (strings .Join (addrs , " " ))
198
201
}
199
202
200
203
// Get returns the value for the address in the map, if present.
You can’t perform that action at this time.
0 commit comments