blob: e8b492774d1af68c84cc16606a47fc4d5526c0b5 [file] [log] [blame]
khenaidoo5fc5cea2021-08-11 17:39:16 -04001/*
2 * Copyright 2021 gRPC authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package internal
18
19import (
20 "google.golang.org/grpc/attributes"
21 "google.golang.org/grpc/resolver"
22)
23
24// handshakeClusterNameKey is the type used as the key to store cluster name in
25// the Attributes field of resolver.Address.
26type handshakeClusterNameKey struct{}
27
28// SetXDSHandshakeClusterName returns a copy of addr in which the Attributes field
29// is updated with the cluster name.
30func SetXDSHandshakeClusterName(addr resolver.Address, clusterName string) resolver.Address {
khenaidoo5cb0d402021-12-08 14:09:16 -050031 addr.Attributes = addr.Attributes.WithValue(handshakeClusterNameKey{}, clusterName)
khenaidoo5fc5cea2021-08-11 17:39:16 -040032 return addr
33}
34
35// GetXDSHandshakeClusterName returns cluster name stored in attr.
36func GetXDSHandshakeClusterName(attr *attributes.Attributes) (string, bool) {
37 v := attr.Value(handshakeClusterNameKey{})
38 name, ok := v.(string)
39 return name, ok
40}