package main import ( "context" "path/filepath" "time" "linkfog.com/public/lib/l" "linkfog.com/pluginx/pluginrpc" ) func main() { pluginConf := make(map[string]string) pluginConf["test-plugin"] = "/tmp/unix_domain.sock" client, err := pluginrpc.NewPluginGrpcClient(pluginConf) if err != nil { l.Error("NewGrpcClientHelper err:", err) return } defer client.Close() call(client) sendFile(client) } func call(client *pluginrpc.PluginGrpcClient) { req := pluginrpc.NewReq("agent", "test-plugin", "Ping", []byte("ping")) l.Info("Call req header:", req.Header) l.Info("Call req data:", string(req.Data)) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() res, err := client.Call(ctx, req) if err != nil { l.Error("Call err:", err) return } l.Info("Call res header:", res.Header) l.Infof("Call res code:%d, desc:%s, data:%s", res.Code, res.Desc, string(res.Data)) } func sendFile(client *pluginrpc.PluginGrpcClient) { filePath := "client" fs := pluginrpc.NewFileStream("agent", "test-plugin", "SendFile", filepath.Base(filePath), "testdata") l.Info("SendFile req header:", fs.Header) l.Infof("SendFile req name:%s, purpose:%s", fs.Name, fs.Purpose) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() res, err := client.SendFile(ctx, fs, filePath) if err != nil { l.Error("SendFile err:", err) return } l.Info("SendFile res header:", res.Header) l.Infof("SendFile res code:%d, desc:%s, data:%s", res.Code, res.Desc, string(res.Data)) }