From 4f3252f57f5febb31c24d3674c7730f3d6cd9b4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 30 Jun 2022 12:05:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=A5=E5=8F=A3=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rpc.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/rpc.go b/rpc.go index 8cfb46a..cf0dd97 100644 --- a/rpc.go +++ b/rpc.go @@ -84,6 +84,17 @@ func (r *request) GetServiceInfo(serviceFlag string) (*Service, error) { return serviceInfo, nil } +// RemoveService 删除一个service +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 11:46 2022/6/30 +func (r *request) RemoveService(serviceFlag string) { + r.lock.Lock() + defer r.lock.Unlock() + delete(r.serviceTable, serviceFlag) +} + // AddServiceApi 向一个service中增加Api // // Author : go_developer@163.com<白茶清欢> @@ -106,3 +117,45 @@ func (r *request) AddServiceApi(serviceFlag string, apiConfig *Api) error { serviceInfo.ApiTable[apiConfig.Flag] = apiConfig return nil } + +// GetServiceApi 获取服务api配置 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 11:53 2022/6/30 +func (r *request) GetServiceApi(serviceFlag string, apiFlag string) (*Service, *Api, error) { + var ( + serviceInfo *Service + err error + exist bool + apiInfo *Api + ) + if serviceInfo, err = r.GetServiceInfo(serviceFlag); nil != err { + return nil, nil, err + } + r.lock.Lock() + defer r.lock.Unlock() + if apiInfo, exist = serviceInfo.ApiTable[apiFlag]; !exist { + return nil, nil, errors.New(serviceFlag + " : " + apiFlag + " -> api") + } + return serviceInfo, apiInfo, nil +} + +// RemoveServiceApi 删除服务下的一个api +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 12:02 2022/6/30 +func (r *request) RemoveServiceApi(serviceFlag string, apiFlag string) { + var ( + serviceInfo *Service + err error + ) + if serviceInfo, _, err = r.GetServiceApi(serviceFlag, apiFlag); nil != err { + // 不存在无需处理 + return + } + r.lock.Lock() + defer r.lock.Unlock() + delete(serviceInfo.ApiTable, apiFlag) +}