golang-im聊天
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

44 lines
965 B

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