You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ioswitch.go 3.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package hubrpc
  2. import (
  3. context "context"
  4. "io"
  5. "gitlink.org.cn/cloudream/common/pkgs/ioswitch/exec"
  6. rpc "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/rpc"
  7. )
  8. type IOSwitchSvc interface {
  9. ExecuteIOPlan(ctx context.Context, req *ExecuteIOPlan) (*ExecuteIOPlanResp, *rpc.CodeError)
  10. SendIOStream(ctx context.Context, req *SendIOStream) (*SendIOStreamResp, *rpc.CodeError)
  11. GetIOStream(ctx context.Context, req *GetIOStream) (*GetIOStreamResp, *rpc.CodeError)
  12. SendIOVar(ctx context.Context, req *SendIOVar) (*SendIOVarResp, *rpc.CodeError)
  13. GetIOVar(ctx context.Context, req *GetIOVar) (*GetIOVarResp, *rpc.CodeError)
  14. }
  15. // 执行IO计划
  16. type ExecuteIOPlan struct {
  17. Plan exec.Plan
  18. }
  19. type ExecuteIOPlanResp struct{}
  20. func (c *Client) ExecuteIOPlan(ctx context.Context, req *ExecuteIOPlan) (*ExecuteIOPlanResp, *rpc.CodeError) {
  21. if c.fusedErr != nil {
  22. return nil, c.fusedErr
  23. }
  24. return rpc.UnaryClient[*ExecuteIOPlanResp](c.cli.ExecuteIOPlan, ctx, req)
  25. }
  26. func (s *Server) ExecuteIOPlan(ctx context.Context, req *rpc.Request) (*rpc.Response, error) {
  27. return rpc.UnaryServer(s.svrImpl.ExecuteIOPlan, ctx, req)
  28. }
  29. // 发送IO流
  30. type SendIOStream struct {
  31. PlanID exec.PlanID
  32. VarID exec.VarID
  33. Stream io.Reader `json:"-"`
  34. }
  35. func (s *SendIOStream) GetStream() io.Reader {
  36. return s.Stream
  37. }
  38. func (s *SendIOStream) SetStream(str io.Reader) {
  39. s.Stream = str
  40. }
  41. type SendIOStreamResp struct{}
  42. func (c *Client) SendIOStream(ctx context.Context, req *SendIOStream) (*SendIOStreamResp, *rpc.CodeError) {
  43. if c.fusedErr != nil {
  44. return nil, c.fusedErr
  45. }
  46. return rpc.UploadStreamClient[*SendIOStreamResp](c.cli.SendIOStream, ctx, req)
  47. }
  48. func (s *Server) SendIOStream(req Hub_SendIOStreamServer) error {
  49. return rpc.UploadStreamServer(s.svrImpl.SendIOStream, req)
  50. }
  51. // 获取IO流
  52. type GetIOStream struct {
  53. PlanID exec.PlanID
  54. VarID exec.VarID
  55. SignalID exec.VarID
  56. Signal exec.VarValue
  57. }
  58. type GetIOStreamResp struct {
  59. Stream io.ReadCloser `json:"-"`
  60. }
  61. func (r *GetIOStreamResp) GetStream() io.ReadCloser {
  62. return r.Stream
  63. }
  64. func (r *GetIOStreamResp) SetStream(str io.ReadCloser) {
  65. r.Stream = str
  66. }
  67. func (c *Client) GetIOStream(ctx context.Context, req *GetIOStream) (*GetIOStreamResp, *rpc.CodeError) {
  68. if c.fusedErr != nil {
  69. return nil, c.fusedErr
  70. }
  71. return rpc.DownloadStreamClient[*GetIOStreamResp](c.cli.GetIOStream, ctx, req)
  72. }
  73. func (s *Server) GetIOStream(req *rpc.Request, ret Hub_GetIOStreamServer) error {
  74. return rpc.DownloadStreamServer(s.svrImpl.GetIOStream, req, ret)
  75. }
  76. // 发送IO变量
  77. type SendIOVar struct {
  78. PlanID exec.PlanID
  79. VarID exec.VarID
  80. Value exec.VarValue
  81. }
  82. type SendIOVarResp struct{}
  83. func (c *Client) SendIOVar(ctx context.Context, req *SendIOVar) (*SendIOVarResp, *rpc.CodeError) {
  84. if c.fusedErr != nil {
  85. return nil, c.fusedErr
  86. }
  87. return rpc.UnaryClient[*SendIOVarResp](c.cli.SendIOVar, ctx, req)
  88. }
  89. func (s *Server) SendIOVar(ctx context.Context, req *rpc.Request) (*rpc.Response, error) {
  90. return rpc.UnaryServer(s.svrImpl.SendIOVar, ctx, req)
  91. }
  92. // 获取IO变量
  93. type GetIOVar struct {
  94. PlanID exec.PlanID
  95. VarID exec.VarID
  96. SignalID exec.VarID
  97. Signal exec.VarValue
  98. }
  99. type GetIOVarResp struct {
  100. Value exec.VarValue
  101. }
  102. func (c *Client) GetIOVar(ctx context.Context, req *GetIOVar) (*GetIOVarResp, *rpc.CodeError) {
  103. if c.fusedErr != nil {
  104. return nil, c.fusedErr
  105. }
  106. return rpc.UnaryClient[*GetIOVarResp](c.cli.GetIOVar, ctx, req)
  107. }
  108. func (s *Server) GetIOVar(ctx context.Context, req *rpc.Request) (*rpc.Response, error) {
  109. return rpc.UnaryServer(s.svrImpl.GetIOVar, ctx, req)
  110. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。