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.

2 年之前
2 年之前
2 年之前
1 年之前
2 年之前
1 年之前
2 年之前
2 年之前
1 年之前
1 年之前
1 年之前
2 年之前
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. }