Files
full/apps/base/sender/cmd/main/main.go

50 lines
1.3 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.
/**
* @作者: david.yan(david.yan@qq.com)
* @日期: 2021-11-26 15:25:03
* @描述: Sender微服务主入口程序提供邮件和短信发送功能
*/
package service
import (
"git.apinb.com/bsm-apps/sender/internal/config"
"git.apinb.com/bsm-apps/sender/internal/impl"
"git.apinb.com/bsm-apps/sender/internal/server"
"git.apinb.com/bsm-sdk/core/service"
)
var (
// ServiceKey 服务标识符,用于配置文件加载和服务注册
ServiceKey = "sender"
)
// main 主函数启动Sender微服务
func Run() {
// 初始化配置文件
config.New(ServiceKey)
// 初始化依赖服务Redis、数据库、Etcd等
impl.NewImpl()
// 初始化gRPC和HTTP服务器
s := server.New(config.Spec.Addr)
// 创建微服务实例
srv := service.New(
s.Grpc,
&service.Options{
Addr: config.Spec.Addr, // 服务监听地址
MsConf: config.Spec.MicroService, // 微服务配置
EtcdClient: impl.EtcdService, // Etcd客户端
GatewayCtx: s.Ctx, // Gateway上下文
GatewayConf: config.Spec.Gateway, // Gateway配置
GatewayMux: s.Mux, // Gateway路由器
},
)
// 确保程序退出时优雅停止服务
defer srv.Stop()
// 启动服务并开始监听请求
srv.Start()
}