...

Source file src/google.golang.org/grpc/internal/xds/xds.go

Documentation: google.golang.org/grpc/internal/xds

     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 xds contains methods to Get/Set handshake cluster names. It is separated
    18  // out from the top level /internal package to avoid circular dependencies.
    19  package xds
    20  
    21  import (
    22  	"google.golang.org/grpc/attributes"
    23  	"google.golang.org/grpc/resolver"
    24  )
    25  
    26  // handshakeClusterNameKey is the type used as the key to store cluster name in
    27  // the Attributes field of resolver.Address.
    28  type handshakeClusterNameKey struct{}
    29  
    30  // SetXDSHandshakeClusterName returns a copy of addr in which the Attributes field
    31  // is updated with the cluster name.
    32  func SetXDSHandshakeClusterName(addr resolver.Address, clusterName string) resolver.Address {
    33  	addr.Attributes = addr.Attributes.WithValue(handshakeClusterNameKey{}, clusterName)
    34  	return addr
    35  }
    36  
    37  // GetXDSHandshakeClusterName returns cluster name stored in attr.
    38  func GetXDSHandshakeClusterName(attr *attributes.Attributes) (string, bool) {
    39  	v := attr.Value(handshakeClusterNameKey{})
    40  	name, ok := v.(string)
    41  	return name, ok
    42  }
    43  

View as plain text