server.go 765 Bytes
Newer Older
Lei Li's avatar
Lei Li committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package plugin

import (
	"context"
	"linkfog.com/pluginx/pluginrpc"
	pb "linkfog.com/pluginx/proto"
	"linkfog.com/public/lib/l"
)

type pluginServer struct {
	pb.UnimplementedPluginServer
}

func newPluginServer() *pluginServer {
	s := &pluginServer{}
	return s
}

func (s *pluginServer) Call(ctx context.Context, req *pb.Req) (*pb.Res, error) {
	res := pluginrpc.NewRes(req, 0, "success", []byte("pong"))
	return res, nil
}

func (s *pluginServer) SendFile(stream pb.Plugin_SendFileServer) error {
	return pluginrpc.SendFileHelper(stream, SendFileHandle)
}

func SendFileHandle(fs *pb.FileStream, filePath string) {
	l.Info("recv file header:", fs.Header)
	l.Infof("recv file name:%s, purpose:%s, size:%d, path:%s", fs.Name, fs.Purpose, fs.TotalSize, filePath)
}