github.com/polarismesh/polaris@v1.17.8/apiserver/grpcserver/utils/help.go (about) 1 /** 2 * Tencent is pleased to support the open source community by making Polaris available. 3 * 4 * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 5 * 6 * Licensed under the BSD 3-Clause License (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * https://opensource.org/licenses/BSD-3-Clause 11 * 12 * Unless required by applicable law or agreed to in writing, software distributed 13 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 14 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 15 * specific language governing permissions and limitations under the License. 16 */ 17 18 package utils 19 20 import ( 21 "fmt" 22 "strings" 23 24 "go.uber.org/zap" 25 26 "github.com/polarismesh/polaris/apiserver" 27 "github.com/polarismesh/polaris/common/log" 28 ) 29 30 // GetClientOpenMethod 获取客户端openMethod 31 func GetClientOpenMethod(include []string, protocol string) (map[string]bool, error) { 32 clientAccess := make(map[string][]string) 33 clientAccess[apiserver.DiscoverAccess] = []string{"Discover", "ReportClient"} 34 clientAccess[apiserver.RegisterAccess] = []string{"RegisterInstance", "DeregisterInstance"} 35 clientAccess[apiserver.HealthcheckAccess] = []string{"Heartbeat", "BatchHeartbeat", "BatchGetHeartbeat", "BatchDelHeartbeat"} 36 37 openMethod := make(map[string]bool) 38 // 如果为空,开启全部接口 39 if len(include) == 0 { 40 for key := range clientAccess { 41 include = append(include, key) 42 } 43 } 44 45 for _, item := range include { 46 if methods, ok := clientAccess[item]; ok { 47 for _, method := range methods { 48 recordMethod := "/v1.Polaris" + strings.ToUpper(protocol) + "/" + method 49 if item == apiserver.HealthcheckAccess && method != "Heartbeat" { 50 recordMethod = "/v1.PolarisHeartbeat" + strings.ToUpper(protocol) + "/" + method 51 } 52 openMethod[recordMethod] = true 53 } 54 } else { 55 log.Errorf("method %s does not exist in %sserver client access", item, protocol) 56 return nil, fmt.Errorf("method %s does not exist in %sserver client access", item, protocol) 57 } 58 } 59 log.Info("[APIServer] client open method info", zap.Any("openMethod", openMethod)) 60 return openMethod, nil 61 }