You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

57 lines
1.2 KiB

  1. package main
  2. import (
  3. "egg-im/config"
  4. "egg-im/internal/logic/api"
  5. "egg-im/internal/logic/app"
  6. "egg-im/internal/logic/proxy"
  7. "egg-im/pkg/db"
  8. "egg-im/pkg/interceptor"
  9. "egg-im/pkg/logger"
  10. "egg-im/pkg/pb"
  11. "egg-im/pkg/urlwhitelist"
  12. "fmt"
  13. "net"
  14. "os"
  15. "os/signal"
  16. "syscall"
  17. "go.uber.org/zap"
  18. "google.golang.org/grpc"
  19. )
  20. func init() {
  21. proxy.MessageProxy = app.MessageApp
  22. proxy.DeviceProxy = app.DeviceApp
  23. }
  24. func main() {
  25. config.Init()
  26. db.Init()
  27. server := grpc.NewServer(grpc.UnaryInterceptor(interceptor.NewInterceptor("logic_interceptor", urlwhitelist.Logic)))
  28. // 监听服务关闭信号,服务平滑重启
  29. go func() {
  30. c := make(chan os.Signal, 1)
  31. signal.Notify(c, syscall.SIGTERM)
  32. s := <-c
  33. logger.Logger.Info("server stop", zap.Any("signal", s))
  34. server.GracefulStop()
  35. }()
  36. pb.RegisterLogicIntServer(server, &api.LogicIntServer{})
  37. pb.RegisterLogicExtServer(server, &api.LogicExtServer{})
  38. fmt.Println("logic::listenAddr>>>>", config.RPCListenAddr)
  39. listen, err := net.Listen("tcp", config.RPCListenAddr)
  40. if err != nil {
  41. panic(err)
  42. }
  43. logger.Logger.Info("rpc服务已经开启")
  44. err = server.Serve(listen)
  45. if err != nil {
  46. logger.Logger.Error("serve error", zap.Error(err))
  47. }
  48. }