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) } }