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

54 行
1.1 KiB

  1. package main
  2. import (
  3. "gim/config"
  4. "gim/internal/business/api"
  5. "gim/pkg/db"
  6. "gim/pkg/interceptor"
  7. "gim/pkg/logger"
  8. "gim/pkg/pb"
  9. "gim/pkg/urlwhitelist"
  10. "net"
  11. "net/http"
  12. _ "net/http/pprof"
  13. "os"
  14. "os/signal"
  15. "syscall"
  16. "go.uber.org/zap"
  17. "google.golang.org/grpc"
  18. )
  19. func main() {
  20. config.Init()
  21. db.Init()
  22. server := grpc.NewServer(grpc.UnaryInterceptor(interceptor.NewInterceptor("business_interceptor", urlwhitelist.Business)))
  23. // 监听服务关闭信号,服务平滑重启
  24. go func() {
  25. c := make(chan os.Signal, 1)
  26. signal.Notify(c, syscall.SIGTERM)
  27. s := <-c
  28. logger.Logger.Info("server stop", zap.Any("signal", s))
  29. server.GracefulStop()
  30. }()
  31. //runtime.SetBlockProfileRate(1)
  32. go func() {
  33. http.ListenAndServe(":10001", nil)
  34. }()
  35. pb.RegisterBusinessIntServer(server, &api.BusinessIntServer{})
  36. pb.RegisterBusinessExtServer(server, &api.BusinessExtServer{})
  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. }