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

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