Files
full/module/base/cms/cmd/main/main.go

56 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* CMS内容管理系统主入口
* @Author: david.yan(david.yan@qq.com)
* @Date: 2021-11-26 15:25:03
* @Description: 提供文章、页面、分类、标签等内容管理功能
*/
package main
import (
"bsm/full/module/base/cms/internal/config"
"bsm/full/module/base/cms/internal/impl"
"bsm/full/module/base/cms/internal/server"
"git.apinb.com/bsm-sdk/core/service"
)
var (
// ServiceKey 服务标识符,用于配置加载和服务注册
ServiceKey = "cms"
)
// main 应用程序主入口函数
// 负责初始化配置、数据库连接、gRPC服务等核心组件
func Run() {
// 初始化配置,加载服务配置参数
config.New(ServiceKey)
// 初始化实现层建立数据库、缓存、etcd等连接
impl.NewImpl()
// 创建gRPC服务器实例监听指定地址
s := server.New(nil)
// 创建微服务实例,配置服务参数
srv := service.New(
s.Grpc,
&service.Options{
Addr: config.Spec.Addr, // 服务监听地址
MsConf: config.Spec.MicroService, // 微服务配置
EtcdClient: impl.EtcdService, // Etcd客户端用于服务发现
GatewayCtx: s.Ctx, // HTTP网关上下文
GatewayConf: config.Spec.Gateway, // HTTP网关配置
GatewayMux: s.Mux, // HTTP网关多路复用器
},
)
// 程序退出时优雅地停止服务,释放资源
defer srv.Stop()
// 启动服务,开始监听和处理请求
srv.Start()
}
func main() {
Run()
}