connectlogic.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package logic
  2. import (
  3. "context"
  4. "ylink/comm/result"
  5. "ylink/core/auth/rpc/auth"
  6. "ylink/flowsrv/rpc/internal/mgr"
  7. "ylink/flowsrv/rpc/internal/svc"
  8. "ylink/flowsrv/rpc/pb"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type ConnectLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewConnectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ConnectLogic {
  17. return &ConnectLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. func (l *ConnectLogic) Connect(in *pb.CommandReq, stream pb.Flowsrv_ConnectServer) error {
  24. authResp, err := l.svcCtx.AuthRpc.CheckAuth(l.ctx, &auth.CheckAuthReq{
  25. Type: in.Type,
  26. AccessToken: in.AccessToken,
  27. })
  28. if err != nil {
  29. return stream.Send(&pb.CommandResp{
  30. Code: result.TokenParseError,
  31. Msg: err.Error(),
  32. Data: nil,
  33. })
  34. }
  35. // update(对接的user的状态也返回)
  36. //stream.RecvMsg()
  37. mgr.GetFlowMgrInstance().SetFlow(authResp.Uid, stream)
  38. return stream.Send(&pb.CommandResp{
  39. Code: result.Ok,
  40. Msg: "success",
  41. Data: nil,
  42. })
  43. }