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 26// Locality is xds.Locality without XXX fields, so it can be used as map 27// keys. 28// 29// xds.Locality cannot be map keys because one of the XXX fields is a slice. 30// 31// This struct should only be used as map keys. Use the proto message directly 32// in all other places. 33type Locality struct { 34 Region string 35 Zone string 36 SubZone string 37} 38 39func (lamk Locality) String() string { 40 return fmt.Sprintf("%s-%s-%s", lamk.Region, lamk.Zone, lamk.SubZone) 41} 42 43// ToProto convert Locality to the proto representation. 44func (lamk Locality) ToProto() *corepb.Locality { 45 return &corepb.Locality{ 46 Region: lamk.Region, 47 Zone: lamk.Zone, 48 SubZone: lamk.SubZone, 49 } 50} 51