1/* 2 * 3 * Copyright 2019 gRPC authors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package internal 19 20import ( 21 "fmt" 22 23 corepb "github.com/envoyproxy/go-control-plane/envoy/api/v2/core" 24) 25 26type clientID string 27 28// XDSClientID is the attributes key used to pass the address of the xdsClient 29// object shared between the resolver and the balancer. The xdsClient object is 30// created by the resolver and passed to the balancer. 31const XDSClientID = clientID("xdsClientID") 32 33// Locality is xds.Locality without XXX fields, so it can be used as map 34// keys. 35// 36// xds.Locality cannot be map keys because one of the XXX fields is a slice. 37// 38// This struct should only be used as map keys. Use the proto message directly 39// in all other places. 40// 41// TODO: rename to LocalityID. 42type Locality struct { 43 Region string 44 Zone string 45 SubZone string 46} 47 48func (lamk Locality) String() string { 49 return fmt.Sprintf("%s-%s-%s", lamk.Region, lamk.Zone, lamk.SubZone) 50} 51 52// ToProto convert Locality to the proto representation. 53func (lamk Locality) ToProto() *corepb.Locality { 54 return &corepb.Locality{ 55 Region: lamk.Region, 56 Zone: lamk.Zone, 57 SubZone: lamk.SubZone, 58 } 59} 60