golang-im聊天
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

51 行
1.1 KiB

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