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