db.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "call_center/db/rpc/internal/config"
  4. "call_center/db/rpc/internal/server"
  5. "call_center/db/rpc/internal/svc"
  6. "call_center/db/rpc/pb"
  7. logic "call_center/public/common"
  8. "flag"
  9. "github.com/tal-tech/go-zero/core/logx"
  10. "log"
  11. "github.com/tal-tech/go-zero/core/conf"
  12. "github.com/tal-tech/go-zero/core/service"
  13. "github.com/tal-tech/go-zero/zrpc"
  14. "google.golang.org/grpc"
  15. "google.golang.org/grpc/reflection"
  16. )
  17. var configFile = flag.String("f", "etc/db.yaml", "the config file")
  18. func main() {
  19. flag.Parse()
  20. logic.PreCheckConfig(*configFile)
  21. var c config.Config
  22. conf.MustLoad(*configFile, &c)
  23. // 日志模块初始化
  24. logx.MustSetup(c.Log)
  25. logx.CollectSysLog()
  26. ctx := svc.NewServiceContext(c)
  27. srv := server.NewDbServer(ctx)
  28. s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
  29. pb.RegisterDbServer(grpcServer, srv)
  30. switch c.Mode {
  31. case service.DevMode, service.TestMode:
  32. reflection.Register(grpcServer)
  33. default:
  34. }
  35. })
  36. defer s.Stop()
  37. log.Printf("Starting rpc server at %s...\n", c.ListenOn)
  38. s.Start()
  39. }