Skip to content

Commit

Permalink
修改说明
Browse files Browse the repository at this point in the history
  • Loading branch information
zkfy committed Jan 31, 2023
1 parent 7fdfe9a commit 446310e
Show file tree
Hide file tree
Showing 3 changed files with 538 additions and 515 deletions.
21 changes: 5 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,6 @@ hydra 提供简单的、统一的、易扩展的服务容器框架。通过少

[hydra](https://github.com/micro-plat/hydra)

[hello world示例](/01guide/01helloworld.md)


[构建六类服务器](/01guide/02servers.md)


[服务运行](/02component/01service.md)


[配置中心](/02component/02conf.md)


- [hydra微服务容器](#hydra微服务容器)
- [一、示例](#一示例)
Expand All @@ -90,11 +79,6 @@ hydra 提供简单的、统一的、易扩展的服务容器框架。通过少
- [四、 服务注册](#四-服务注册)
- [五、 服务响应](#五-服务响应)

架构图

![image](https://github.com/micro-plat/hydra/raw/master/hydra.png)





Expand Down Expand Up @@ -692,3 +676,8 @@ func request(ctx hydra.IContext) interface{} {
> Content-Type: text/plain; charset=utf-8

架构图

![image](https://github.com/micro-plat/hydra/raw/master/hydra.png)


296 changes: 165 additions & 131 deletions conf/app/app.go
Original file line number Diff line number Diff line change
@@ -1,131 +1,165 @@
package app

import (
"fmt"

"github.com/micro-plat/hydra/conf"
"github.com/micro-plat/hydra/conf/server"
"github.com/micro-plat/hydra/conf/server/acl/blacklist"
"github.com/micro-plat/hydra/conf/server/acl/limiter"
"github.com/micro-plat/hydra/conf/server/acl/proxy"
"github.com/micro-plat/hydra/conf/server/acl/whitelist"
"github.com/micro-plat/hydra/conf/server/apm"
"github.com/micro-plat/hydra/conf/server/auth/apikey"
"github.com/micro-plat/hydra/conf/server/auth/basic"
"github.com/micro-plat/hydra/conf/server/auth/jwt"
"github.com/micro-plat/hydra/conf/server/auth/ras"
"github.com/micro-plat/hydra/conf/server/header"
"github.com/micro-plat/hydra/conf/server/metric"
"github.com/micro-plat/hydra/conf/server/mqc"
"github.com/micro-plat/hydra/conf/server/nfs"
"github.com/micro-plat/hydra/conf/server/processor"
"github.com/micro-plat/hydra/conf/server/queue"
"github.com/micro-plat/hydra/conf/server/render"
"github.com/micro-plat/hydra/conf/server/static"
"github.com/micro-plat/hydra/conf/server/task"
"github.com/micro-plat/hydra/conf/vars"
"github.com/micro-plat/hydra/conf/vars/rlog"
"github.com/micro-plat/hydra/global"
"github.com/micro-plat/hydra/registry"
)

//IAPPConf 服务器配置信息
type IAPPConf interface {
GetServerConf() conf.IServerConf
GetVarConf() conf.IVarConf

GetMQCMainConf() (*mqc.Server, error)
GetMQCQueueConf() (*queue.Queues, error)

GetCRONTaskConf() (*task.Tasks, error)

GetJWTConf() (*jwt.JWTAuth, error)
GetHeaderConf() (header.Headers, error)
GetMetricConf() (*metric.Metric, error)
GetStaticConf() (*static.Static, error)
GetAPIKeyConf() (*apikey.APIKeyAuth, error)
GetRASConf() (*ras.RASAuth, error)
GetBasicConf() (*basic.BasicAuth, error)
GetRenderConf() (*render.Render, error)
GetWhiteListConf() (*whitelist.WhiteList, error)
GetBlackListConf() (*blacklist.BlackList, error)
GetLimiterConf() (*limiter.Limiter, error)
GetProxyConf() (*proxy.Proxy, error)
GetAPMConf() (*apm.APM, error)
GetProcessorConf() (*processor.Processor, error)

GetNFSConf() (*nfs.NFS, error)
//获取远程日志配置
GetRLogConf() (*rlog.Layout, error)

Close() error
}

var _ IAPPConf = &APPConf{}

//APPConf 应用配置信息
type APPConf struct {
serverConf conf.IServerConf
varConf conf.IVarConf
*server.HttpSub
*server.CronSub
*server.MQCSub
*vars.VarSub
}

//NewAPPConfBy 构建服务器配置缓存
func NewAPPConfBy(platName, sysName, serverType, clusterName string, rgst registry.IRegistry) (s *APPConf, err error) {
s = &APPConf{}

//构建server配置
s.serverConf, err = server.NewServerConf(platName, sysName, serverType, clusterName, rgst)
if err != nil {
return nil, err
}

//构建var配置
s.varConf, err = vars.NewVarConf(platName, rgst)
if err != nil {
return nil, err
}

//构建server的组件配置(todo:移到server配置内)
s.HttpSub = server.NewHttpSub(s.serverConf)
s.CronSub = server.NewCronSub(s.serverConf)
s.MQCSub = server.NewMQCSub(s.serverConf)
s.VarSub = vars.NewVarSub(s.varConf)
return s, nil

}

// NewAPPConf 构建服务器配置
func NewAPPConf(mainConfpath string, rgst registry.IRegistry) (s *APPConf, err error) {

//处理平台名、系统名包含多段问题
//获取服务器类型
list := registry.Split(registry.Trim(mainConfpath))
tp := list[len(list)-3]

//无法准确获得平台、系统名,只能通过当前应用配置获得,再比较
pub := server.NewServerPub(global.Def.PlatName, global.Def.SysName, tp, global.Def.ClusterName)
if pub.GetServerPath() != mainConfpath {
return nil, fmt.Errorf("非当前平台、系统、集群的服务不支持获取APPConf")
}
return NewAPPConfBy(global.Def.PlatName, global.Def.SysName, tp, global.Def.ClusterName, rgst)

}

//Close 关闭清理资源
func (s *APPConf) Close() error {
return s.serverConf.Close()
}

//GetServerConf 获取server配置
func (s *APPConf) GetServerConf() conf.IServerConf {
return s.serverConf
}

//GetVarConf 获取var配置
func (s *APPConf) GetVarConf() conf.IVarConf {
return s.varConf
}
package app

import (
"fmt"

"github.com/micro-plat/hydra/conf"
"github.com/micro-plat/hydra/conf/server"
"github.com/micro-plat/hydra/conf/server/acl/blacklist"
"github.com/micro-plat/hydra/conf/server/acl/limiter"
"github.com/micro-plat/hydra/conf/server/acl/proxy"
"github.com/micro-plat/hydra/conf/server/acl/whitelist"
"github.com/micro-plat/hydra/conf/server/apm"
"github.com/micro-plat/hydra/conf/server/auth/apikey"
"github.com/micro-plat/hydra/conf/server/auth/basic"
"github.com/micro-plat/hydra/conf/server/auth/jwt"
"github.com/micro-plat/hydra/conf/server/auth/ras"
"github.com/micro-plat/hydra/conf/server/header"
"github.com/micro-plat/hydra/conf/server/metric"
"github.com/micro-plat/hydra/conf/server/mqc"
"github.com/micro-plat/hydra/conf/server/nfs"
"github.com/micro-plat/hydra/conf/server/processor"
"github.com/micro-plat/hydra/conf/server/queue"
"github.com/micro-plat/hydra/conf/server/render"
"github.com/micro-plat/hydra/conf/server/static"
"github.com/micro-plat/hydra/conf/server/task"
"github.com/micro-plat/hydra/conf/vars"
"github.com/micro-plat/hydra/conf/vars/rlog"
"github.com/micro-plat/hydra/global"
"github.com/micro-plat/hydra/registry"
)

//IAPPConf 服务器配置信息
type IAPPConf interface {
//GetServerConf 获取服务器配置
GetServerConf() conf.IServerConf

//GetVarConf 获取全局参数配置
GetVarConf() conf.IVarConf

//GetMQCMainConf 获取MQC服务配置
GetMQCMainConf() (*mqc.Server, error)

//GetMQCQueueConf 获取MQC监听队列配置
GetMQCQueueConf() (*queue.Queues, error)

//GetCRONTaskConf 获取cron任务配置
GetCRONTaskConf() (*task.Tasks, error)

//GetJWTConf 获取JWT配置
GetJWTConf() (*jwt.JWTAuth, error)

//GetHeaderConf 获取响应头默认配置
GetHeaderConf() (header.Headers, error)

//GetMetricConf 获取服务监控配置
GetMetricConf() (*metric.Metric, error)

//GetStaticConf 获取静态文件配置
GetStaticConf() (*static.Static, error)

//GetAPIKeyConf 获取API KEY配置
GetAPIKeyConf() (*apikey.APIKeyAuth, error)

//GetRASConf 获取RAS远程认证服务配置
GetRASConf() (*ras.RASAuth, error)

//GetBasicConf 获取basic auth配置
GetBasicConf() (*basic.BasicAuth, error)

//GetRenderConf 获取响应输出配置
GetRenderConf() (*render.Render, error)

//GetWhiteListConf 获取白名单配置
GetWhiteListConf() (*whitelist.WhiteList, error)

//GetBlackListConf 获取黑名单配置
GetBlackListConf() (*blacklist.BlackList, error)

//GetLimiterConf 获取限流配置
GetLimiterConf() (*limiter.Limiter, error)

//GetProxyConf 获取转发代理配置
GetProxyConf() (*proxy.Proxy, error)
GetAPMConf() (*apm.APM, error)

//GetProcessorConf 获取服务器处理程序配置
GetProcessorConf() (*processor.Processor, error)

//GetNFSConf 获取文件同步系统配置
GetNFSConf() (*nfs.NFS, error)

//GetRLogConf 获取远程日志配置
GetRLogConf() (*rlog.Layout, error)

Close() error
}

var _ IAPPConf = &APPConf{}

//APPConf 应用配置信息
type APPConf struct {
serverConf conf.IServerConf
varConf conf.IVarConf
*server.HttpSub
*server.CronSub
*server.MQCSub
*vars.VarSub
}

//NewAPPConfBy 构建服务器配置缓存
func NewAPPConfBy(platName, sysName, serverType, clusterName string, rgst registry.IRegistry) (s *APPConf, err error) {
s = &APPConf{}

//构建server配置
s.serverConf, err = server.NewServerConf(platName, sysName, serverType, clusterName, rgst)
if err != nil {
return nil, err
}

//构建var配置
s.varConf, err = vars.NewVarConf(platName, rgst)
if err != nil {
return nil, err
}

//构建server的组件配置(todo:移到server配置内)
s.HttpSub = server.NewHttpSub(s.serverConf)
s.CronSub = server.NewCronSub(s.serverConf)
s.MQCSub = server.NewMQCSub(s.serverConf)
s.VarSub = vars.NewVarSub(s.varConf)
return s, nil

}

// NewAPPConf 构建服务器配置
func NewAPPConf(mainConfpath string, rgst registry.IRegistry) (s *APPConf, err error) {

//处理平台名、系统名包含多段问题
//获取服务器类型
list := registry.Split(registry.Trim(mainConfpath))
tp := list[len(list)-3]

//无法准确获得平台、系统名,只能通过当前应用配置获得,再比较
pub := server.NewServerPub(global.Def.PlatName, global.Def.SysName, tp, global.Def.ClusterName)
if pub.GetServerPath() != mainConfpath {
return nil, fmt.Errorf("非当前平台、系统、集群的服务不支持获取APPConf")
}
return NewAPPConfBy(global.Def.PlatName, global.Def.SysName, tp, global.Def.ClusterName, rgst)

}

//Close 关闭清理资源
func (s *APPConf) Close() error {
return s.serverConf.Close()
}

//GetServerConf 获取server配置
func (s *APPConf) GetServerConf() conf.IServerConf {
return s.serverConf
}

//GetVarConf 获取var配置
func (s *APPConf) GetVarConf() conf.IVarConf {
return s.varConf
}
Loading

0 comments on commit 446310e

Please sign in to comment.