golang-im聊天
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.
 
 
 
 

55 rivejä
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/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. }