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

rpc

上级 c03f5474
......@@ -6,6 +6,7 @@ import (
"time"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/config"
"gitlab.wanzhuangkj.com/tush/xpkg/rpc"
"github.com/jinzhu/copier"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/oss"
......@@ -123,6 +124,7 @@ type Config struct {
Cron Cron `yaml:"cron" json:"cron" mapstructure:"cron"`
Oss oss.AliOssConfig `yaml:"oss" json:"oss" mapstructure:"oss"`
Email config.Config `yaml:"email" json:"email" mapstructure:"email"`
Rpc rpc.Rpc `yaml:"rpc" json:"rpc" mapstructure:"rpc"`
Content []byte `yaml:"-" json:"-"`
}
......
......@@ -12,6 +12,7 @@ const (
API_GET_BY_IDS = "getByIDs"
API_PAGE = "page"
API_JPAGE = "jpage"
API_JLIST = "jlist"
API_EXPORT_CSV = "exportCSV"
)
......
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 {
SrvAddr string `yaml:"srvAddr"`
Groups []Group `yaml:"groups"`
Name string `yaml:"name" json:"name" mapstructure:"name"`
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的组
type Group struct {
Name string `yaml:"name"`
Apis []Api `yaml:"apis"`
Name string `yaml:"name" json:"name" mapstructure:"name"`
Apis []*Api `yaml:"apis" json:"apis" mapstructure:"apis"`
}
// Api 服务的某个接口
type Api struct {
Name string `yaml:"name"`
URI string `yaml:"uri"`
Name string `yaml:"name" json:"name" mapstructure:"name"`
URI string `yaml:"uri" json:"uri" mapstructure:"uri"`
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论