call.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package main
  2. import (
  3. "call_center/call/rpc/internal/core"
  4. "call_center/call/rpc/pb"
  5. logic "call_center/public/common"
  6. "flag"
  7. "fmt"
  8. "call_center/call/rpc/internal/config"
  9. "call_center/call/rpc/internal/server"
  10. "call_center/call/rpc/internal/svc"
  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/call.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. ctx := svc.NewServiceContext(c)
  24. srv := server.NewCallServer(ctx)
  25. s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
  26. pb.RegisterCallServer(grpcServer, srv)
  27. switch c.Mode {
  28. case service.DevMode, service.TestMode:
  29. reflection.Register(grpcServer)
  30. default:
  31. }
  32. })
  33. defer s.Stop()
  34. // core server init
  35. core.ServerInit(c.CoreConf)
  36. // start db
  37. if ctx.Db != nil {
  38. go ctx.Db.Start()
  39. }
  40. fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
  41. s.Start()
  42. }