github.com/polarismesh/polaris@v1.17.8/apiserver/httpserver/config/client_access.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 config 19 20 import ( 21 "strconv" 22 23 "github.com/emicklei/go-restful/v3" 24 apiconfig "github.com/polarismesh/specification/source/go/api/v1/config_manage" 25 apimodel "github.com/polarismesh/specification/source/go/api/v1/model" 26 "google.golang.org/protobuf/types/known/wrapperspb" 27 28 httpcommon "github.com/polarismesh/polaris/apiserver/httpserver/utils" 29 api "github.com/polarismesh/polaris/common/api/v1" 30 ) 31 32 func (h *HTTPServer) ClientGetConfigFile(req *restful.Request, rsp *restful.Response) { 33 handler := &httpcommon.Handler{ 34 Request: req, 35 Response: rsp, 36 } 37 38 version, _ := strconv.ParseUint(handler.Request.QueryParameter("version"), 10, 64) 39 configFile := &apiconfig.ClientConfigFileInfo{ 40 Namespace: &wrapperspb.StringValue{Value: handler.Request.QueryParameter("namespace")}, 41 Group: &wrapperspb.StringValue{Value: handler.Request.QueryParameter("group")}, 42 FileName: &wrapperspb.StringValue{Value: handler.Request.QueryParameter("fileName")}, 43 Version: &wrapperspb.UInt64Value{Value: version}, 44 } 45 46 response := h.configServer.GetConfigFileForClient(handler.ParseHeaderContext(), configFile) 47 handler.WriteHeaderAndProto(response) 48 } 49 50 func (h *HTTPServer) ClientWatchConfigFile(req *restful.Request, rsp *restful.Response) { 51 handler := &httpcommon.Handler{ 52 Request: req, 53 Response: rsp, 54 } 55 56 // 1. 解析出客户端监听的配置文件列表 57 watchConfigFileRequest := &apiconfig.ClientWatchConfigFileRequest{} 58 if _, err := handler.Parse(watchConfigFileRequest); err != nil { 59 handler.WriteHeaderAndProto(api.NewResponseWithMsg(apimodel.Code_ParseException, err.Error())) 60 return 61 } 62 63 // 阻塞等待响应 64 callback, err := h.configServer.WatchConfigFiles(handler.ParseHeaderContext(), watchConfigFileRequest) 65 if err != nil { 66 handler.WriteHeaderAndProto(api.NewResponseWithMsg(apimodel.Code_ExecuteException, err.Error())) 67 return 68 } 69 handler.WriteHeaderAndProto(callback()) 70 } 71 72 // GetConfigFileMetadataList 统一发现接口 73 func (h *HTTPServer) GetConfigFileMetadataList(req *restful.Request, rsp *restful.Response) { 74 handler := &httpcommon.Handler{ 75 Request: req, 76 Response: rsp, 77 } 78 79 in := &apiconfig.ConfigFileGroupRequest{} 80 ctx, err := handler.Parse(in) 81 if err != nil { 82 handler.WriteHeaderAndProto(api.NewResponseWithMsg(apimodel.Code_ParseException, err.Error())) 83 return 84 } 85 out := h.configServer.GetConfigFileNamesWithCache(ctx, in) 86 handler.WriteHeaderAndProto(out) 87 }