支持从配置文件及配置目录初始化RPC服务
This commit is contained in:
parent
09e47648bc
commit
54aef081d9
1
go.mod
1
go.mod
@ -34,6 +34,7 @@ require (
|
|||||||
golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b // indirect
|
golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b // indirect
|
||||||
golang.org/x/text v0.3.7 // indirect
|
golang.org/x/text v0.3.7 // indirect
|
||||||
google.golang.org/protobuf v1.28.0 // 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.v2 v2.4.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
2
go.sum
2
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 h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
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/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.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 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
|
@ -94,5 +94,6 @@ func (r *result) ParseXml(inputContent []byte, receiver interface{}) error {
|
|||||||
//
|
//
|
||||||
// Date : 11:11 2022/7/1
|
// Date : 11:11 2022/7/1
|
||||||
func (r *result) ParseIni(inputContent []byte, receiver interface{}) error {
|
func (r *result) ParseIni(inputContent []byte, receiver interface{}) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
38
rpc.go
38
rpc.go
@ -14,6 +14,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -53,6 +54,43 @@ func InitRPC(serviceTable map[string]*Service, loggerInstance *zap.Logger) error
|
|||||||
return nil
|
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 {
|
type request struct {
|
||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
serviceTable map[string]*Service
|
serviceTable map[string]*Service
|
||||||
|
Loading…
Reference in New Issue
Block a user