finclip-app-manager/main.go

67 lines
1.5 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package main
import (
grpcHandler "finclip-app-manager/application/grpc"
"finclip-app-manager/domain"
"finclip-app-manager/domain/service"
"finclip-app-manager/infrastructure/config"
"finclip-app-manager/infrastructure/consul"
"finclip-app-manager/infrastructure/db/repo/mongo"
"finclip-app-manager/infrastructure/db/repo/mysql"
"finclip-app-manager/infrastructure/kafka"
"finclip-app-manager/infrastructure/logger"
pb "finclip-app-manager/infrastructure/protobuf/golang"
"finclip-app-manager/router"
"net"
"github.com/gin-gonic/gin"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
func main() {
logger.GetLogger().Infof("Start service...")
start()
cfg := config.GetConfig()
gin.SetMode(cfg.Mode)
g := gin.Default()
router.Load(g)
_ = g.Run(":" + cfg.HttpPort)
}
func start() {
go initGrpc()
if config.Cfg.DBMode == "mysql" {
mysql.StartUp(config.Cfg.MysqlUrl)
} else {
mongo.Start()
}
service.InitTypeConfig()
kafka.Start()
service.LicenceCheckStart()
domain.Start()
//redis.Start()
}
func initGrpc() {
cfg := config.GetConfig()
if cfg.ConsulAddr == "" {
return
}
logger.GetLogger().Infof("grcp start ... ")
consul.InitConsul()
//TODO 下面真实开启grpc的例子需要根据实际情况修改下面代码
lis, err := net.Listen("tcp", ":"+cfg.GrpcPort)
if err != nil {
panic(err)
}
s := grpc.NewServer()
pb.RegisterMopAppManageSvrServer(s, &grpcHandler.GrpcServer{})
reflection.Register(s)
if err = s.Serve(lis); err != nil {
panic(err)
}
}