MCPcopy
hub / github.com/grpc/grpc-go / RLSKey

Method RLSKey

balancer/rls/internal/keys/builder.go:122–151  ·  view source on GitHub ↗

RLSKey builds the RLS keys to be used for the given request, identified by the request path and the request headers stored in metadata.

(md metadata.MD, host, path string)

Source from the content-addressed store, hash-verified

120// RLSKey builds the RLS keys to be used for the given request, identified by
121// the request path and the request headers stored in metadata.
122func (bm BuilderMap) RLSKey(md metadata.MD, host, path string) KeyMap {
123 // The path passed in is of the form "/service/method". The keyBuilderMap is
124 // indexed with keys of the form "/service/" or "/service/method". The service
125 // that we set in the keyMap (to be sent out in the RLS request) should not
126 // include any slashes though.
127 i := strings.LastIndex(path, "/")
128 service, method := path[:i+1], path[i+1:]
129 b, ok := bm[path]
130 if !ok {
131 b, ok = bm[service]
132 if !ok {
133 return KeyMap{}
134 }
135 }
136
137 kvMap := b.buildHeaderKeys(md)
138 if b.hostKey != "" {
139 kvMap[b.hostKey] = host
140 }
141 if b.serviceKey != "" {
142 kvMap[b.serviceKey] = strings.Trim(service, "/")
143 }
144 if b.methodKey != "" {
145 kvMap[b.methodKey] = method
146 }
147 for k, v := range b.constantKeys {
148 kvMap[k] = v
149 }
150 return KeyMap{Map: kvMap, Str: mapToString(kvMap)}
151}
152
153// Equal reports whether bm and am represent equivalent BuilderMaps.
154func (bm BuilderMap) Equal(am BuilderMap) bool {

Callers 2

PickMethod · 0.80
TestRLSKeyFunction · 0.80

Calls 2

mapToStringFunction · 0.85
buildHeaderKeysMethod · 0.80

Tested by 1

TestRLSKeyFunction · 0.64