gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

xds_handshake_cluster.go (1411B)


      1 /*
      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 
     17 package internal
     18 
     19 import (
     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.
     26 type handshakeClusterNameKey struct{}
     27 
     28 // SetXDSHandshakeClusterName returns a copy of addr in which the Attributes field
     29 // is updated with the cluster name.
     30 func SetXDSHandshakeClusterName(addr resolver.Address, clusterName string) resolver.Address {
     31 	addr.Attributes = addr.Attributes.WithValue(handshakeClusterNameKey{}, clusterName)
     32 	return addr
     33 }
     34 
     35 // GetXDSHandshakeClusterName returns cluster name stored in attr.
     36 func GetXDSHandshakeClusterName(attr *attributes.Attributes) (string, bool) {
     37 	v := attr.Value(handshakeClusterNameKey{})
     38 	name, ok := v.(string)
     39 	return name, ok
     40 }