github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/grpc/xds/internal/xdsclient/dump.go (about) 1 /* 2 * 3 * Copyright 2021 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 */ 18 19 package xdsclient 20 21 import ( 22 "github.com/hxx258456/ccgo/grpc/xds/internal/xdsclient/xdsresource" 23 ) 24 25 func mergeMaps(maps []map[string]xdsresource.UpdateWithMD) map[string]xdsresource.UpdateWithMD { 26 ret := make(map[string]xdsresource.UpdateWithMD) 27 for _, m := range maps { 28 for k, v := range m { 29 ret[k] = v 30 } 31 } 32 return ret 33 } 34 35 func (c *clientImpl) dump(t xdsresource.ResourceType) map[string]xdsresource.UpdateWithMD { 36 c.authorityMu.Lock() 37 defer c.authorityMu.Unlock() 38 maps := make([]map[string]xdsresource.UpdateWithMD, 0, len(c.authorities)) 39 for _, a := range c.authorities { 40 maps = append(maps, a.dump(t)) 41 } 42 return mergeMaps(maps) 43 } 44 45 // DumpLDS returns the status and contents of LDS. 46 func (c *clientImpl) DumpLDS() map[string]xdsresource.UpdateWithMD { 47 return c.dump(xdsresource.ListenerResource) 48 } 49 50 // DumpRDS returns the status and contents of RDS. 51 func (c *clientImpl) DumpRDS() map[string]xdsresource.UpdateWithMD { 52 return c.dump(xdsresource.RouteConfigResource) 53 } 54 55 // DumpCDS returns the status and contents of CDS. 56 func (c *clientImpl) DumpCDS() map[string]xdsresource.UpdateWithMD { 57 return c.dump(xdsresource.ClusterResource) 58 } 59 60 // DumpEDS returns the status and contents of EDS. 61 func (c *clientImpl) DumpEDS() map[string]xdsresource.UpdateWithMD { 62 return c.dump(xdsresource.EndpointsResource) 63 }