Ai
1 Star 0 Fork 0

csingo/cServer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Server.go 2.03 KB
一键复制 编辑 原始数据 按行查看 历史
joe 提交于 2024-12-17 11:14 +08:00 . update
package cServer
import (
"fmt"
"github.com/gin-gonic/gin"
"gitee.com/csingo/cComponents"
"gitee.com/csingo/cLog"
)
var (
version = "unknown"
)
func Routes() []*RouteItem {
return container.routes
}
func Inject(instance any) {
Component.Inject(instance)
if cComponents.IsConf(instance) {
Component.InjectConf(instance.(cComponents.ConfigInterface))
cLog.Component.InjectConf(instance.(cComponents.ConfigInterface))
}
}
func Load() {
fmt.Println("version", version)
Initialize()
// 启动 HTTP 服务
go startHTTP()
// 启动 GRPC 服务
go startGRPC()
// server component 初始化
Component.Load()
}
func Initialize() {
// 依赖注入
container.DI()
// 初始化组件
initComponents()
// 初始化路由
container.ParseRoute(route_config, []gin.HandlerFunc{}, []string{}, "")
}
func initComponents() {
// 优先加载日志组件
cLog.Component.Load()
// 组件实例注入 && 组件配置注入
container.Range(func(item any) {
if item != nil && len(components_config.Components) > 0 {
for _, component := range components_config.Components {
if _, isServerComponent := component.(*ServerComponent); isServerComponent {
continue
}
component.Inject(item)
if cComponents.IsConf(item) {
component.InjectConf(item.(cComponents.ConfigInterface))
}
}
}
})
// 组件初始化 && 获取组件配置监听函数
var listeners = make([]*cComponents.ConfigListener, 0)
for _, component := range components_config.Components {
listener := component.Listen()
listeners = append(listeners, listener...)
if _, isServerComponent := component.(*ServerComponent); !isServerComponent {
component.Load()
}
}
// 注入监听器
var configComponent cComponents.ComponentInterface
for _, listener := range listeners {
if configComponent == nil {
for _, component := range components_config.Components {
if component.Inject(listener) {
configComponent = component
}
}
} else {
configComponent.Inject(listener)
}
}
}
func GetVersion() string {
return version
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/csingo/cServer.git
git@gitee.com:csingo/cServer.git
csingo
cServer
cServer
v0.4.27

搜索帮助