From 54aef081d9c513833390d6202fd1f53b4f809811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 1 Jul 2022 17:51:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=8F=8A=E9=85=8D=E7=BD=AE=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96RPC=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 1 + go.sum | 2 ++ result.go | 1 + rpc.go | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+) diff --git a/go.mod b/go.mod index e10cfa5..72f793d 100644 --- a/go.mod +++ b/go.mod @@ -34,6 +34,7 @@ require ( golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b // indirect golang.org/x/text v0.3.7 // indirect google.golang.org/protobuf v1.28.0 // indirect + gopkg.in/ini.v1 v1.66.6 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 8d1ec7d..3a41afd 100644 --- a/go.sum +++ b/go.sum @@ -143,6 +143,8 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/ini.v1 v1.66.6 h1:LATuAqN/shcYAOkv3wl2L4rkaKqkcgTBQjOyYDvcPKI= +gopkg.in/ini.v1 v1.66.6/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/result.go b/result.go index 975755c..f7f421c 100644 --- a/result.go +++ b/result.go @@ -94,5 +94,6 @@ func (r *result) ParseXml(inputContent []byte, receiver interface{}) error { // // Date : 11:11 2022/7/1 func (r *result) ParseIni(inputContent []byte, receiver interface{}) error { + return nil } diff --git a/rpc.go b/rpc.go index a53d5a7..65e150f 100644 --- a/rpc.go +++ b/rpc.go @@ -14,6 +14,7 @@ import ( "fmt" "io" "net/http" + "path/filepath" "strings" "sync" @@ -53,6 +54,43 @@ func InitRPC(serviceTable map[string]*Service, loggerInstance *zap.Logger) error return nil } +// InitRPCFromCfgDir 使用RPC配置文件路径初始化RPC +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 17:41 2022/7/1 +func InitRPCFromCfgDir(cfgDir string, logger *zap.Logger) error { + serviceTable := make(map[string]*Service) + filepathNames, _ := filepath.Glob(filepath.Join(cfgDir, "*")) + for i := range filepathNames { + var ( + serviceInfo Service + err error + ) + if err = util.File.ReadJSONContent(cfgDir+string(filepath.Separator)+filepathNames[i], &serviceInfo); nil != err { + return err + } + serviceTable[serviceInfo.Flag] = &serviceInfo + } + return InitRPC(serviceTable, logger) +} + +// InitRPCFromCfgFile 从配置文件初始化RPC服务 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 17:42 2022/7/1 +func InitRPCFromCfgFile(cfgFile string, logger *zap.Logger) error { + var ( + serviceTable map[string]*Service + err error + ) + if err = util.File.ReadJSONContent(cfgFile, &serviceTable); nil != err { + return err + } + return InitRPC(serviceTable, logger) +} + type request struct { logger *zap.Logger serviceTable map[string]*Service