提交 7975d392 authored 作者: mooncake's avatar mooncake

rpc

上级 c03f5474
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"time" "time"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/config" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/config"
"gitlab.wanzhuangkj.com/tush/xpkg/rpc"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/oss" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/oss"
...@@ -123,6 +124,7 @@ type Config struct { ...@@ -123,6 +124,7 @@ type Config struct {
Cron Cron `yaml:"cron" json:"cron" mapstructure:"cron"` Cron Cron `yaml:"cron" json:"cron" mapstructure:"cron"`
Oss oss.AliOssConfig `yaml:"oss" json:"oss" mapstructure:"oss"` Oss oss.AliOssConfig `yaml:"oss" json:"oss" mapstructure:"oss"`
Email config.Config `yaml:"email" json:"email" mapstructure:"email"` Email config.Config `yaml:"email" json:"email" mapstructure:"email"`
Rpc rpc.Rpc `yaml:"rpc" json:"rpc" mapstructure:"rpc"`
Content []byte `yaml:"-" json:"-"` Content []byte `yaml:"-" json:"-"`
} }
......
...@@ -12,6 +12,7 @@ const ( ...@@ -12,6 +12,7 @@ const (
API_GET_BY_IDS = "getByIDs" API_GET_BY_IDS = "getByIDs"
API_PAGE = "page" API_PAGE = "page"
API_JPAGE = "jpage" API_JPAGE = "jpage"
API_JLIST = "jlist"
API_EXPORT_CSV = "exportCSV" API_EXPORT_CSV = "exportCSV"
) )
......
package rpc package rpc
// Svc 服务 type RpcM struct {
M map[string]*Svc
}
func (x *RpcM) GetSvc(name string) *Svc {
return x.M[name]
}
func (x *RpcM) GetGroup(svcName, groupName string) *Group {
svc := x.GetSvc(svcName)
if svc == nil {
return nil
}
return svc.GetGroup(groupName)
}
func (x *RpcM) GetSvcGroup(svcName, groupName string) (*Svc, *Group) {
svc := x.GetSvc(svcName)
if svc == nil {
return nil, nil
}
return svc, svc.GetGroup(groupName)
}
func NewRpcM(rpc Rpc) *RpcM {
ret := RpcM{
M: make(map[string]*Svc),
}
for _, r := range rpc {
ret.M[r.Name] = &r
}
return &ret
}
type Rpc []Svc
type Svc struct { type Svc struct {
SrvAddr string `yaml:"srvAddr"` Name string `yaml:"name" json:"name" mapstructure:"name"`
Groups []Group `yaml:"groups"` SrvAddr string `yaml:"srvAddr" json:"srvAddr" mapstructure:"srvAddr"`
Groups []*Group `yaml:"groups" json:"groups" mapstructure:"groups"`
}
func (x *Svc) GetGroup(groupName string) *Group {
for _, g := range x.Groups {
if g.Name == groupName {
return g
}
}
return nil
} }
// Group api的组 // Group api的组
type Group struct { type Group struct {
Name string `yaml:"name"` Name string `yaml:"name" json:"name" mapstructure:"name"`
Apis []Api `yaml:"apis"` Apis []*Api `yaml:"apis" json:"apis" mapstructure:"apis"`
} }
// Api 服务的某个接口 // Api 服务的某个接口
type Api struct { type Api struct {
Name string `yaml:"name"` Name string `yaml:"name" json:"name" mapstructure:"name"`
URI string `yaml:"uri"` URI string `yaml:"uri" json:"uri" mapstructure:"uri"`
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论