From 12880e9ab315f6f5c2eb12d8a5e984a8266ea4fb Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sat, 5 Nov 2022 23:19:09 +0100 Subject: [PATCH] WIP --- pkg/register/plugin.go | 7 ++++++- pkg/register/plugin_client.go | 17 ++--------------- pkg/register/plugin_register.go | 5 ++++- pkg/register/plugin_server.go | 4 ++-- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/pkg/register/plugin.go b/pkg/register/plugin.go index fd492d9..7a0e13d 100644 --- a/pkg/register/plugin.go +++ b/pkg/register/plugin.go @@ -16,9 +16,14 @@ type About struct { Commands []*AboutCommand `json:"commands"` } +type DoCommand struct { + CommandName string `json:"commandName"` + Args map[string]string `json:"args"` +} + type Plugin interface { About(ctx context.Context) (*About, error) - Do(ctx context.Context, commandName string, args map[string]string) error + Do(ctx context.Context, cmd *DoCommand) error } const PluginKey = "plugin" diff --git a/pkg/register/plugin_client.go b/pkg/register/plugin_client.go index 194fbaf..96d77eb 100644 --- a/pkg/register/plugin_client.go +++ b/pkg/register/plugin_client.go @@ -10,22 +10,9 @@ type PluginClient struct { client *rpc.Client } -type DoRequest struct { - CommandName string `json:"commandName"` - Args map[string]string `json:"args"` -} - // Do implements Plugin -func (pc *PluginClient) Do(ctx context.Context, commandName string, args map[string]string) error { - req := &DoRequest{ - CommandName: commandName, - Args: args, - } - //doReq, err := json.Marshal(req) - //if err != nil { - // return err - //} - err := pc.client.Call("Plugin.Do", req, new(any)) +func (pc *PluginClient) Do(ctx context.Context, cmd *DoCommand) error { + err := pc.client.Call("Plugin.Do", cmd, new(string)) if err != nil { return err } diff --git a/pkg/register/plugin_register.go b/pkg/register/plugin_register.go index 705c565..2e8b67e 100644 --- a/pkg/register/plugin_register.go +++ b/pkg/register/plugin_register.go @@ -234,7 +234,10 @@ func (pr *PluginRegister) Do(ctx context.Context, clientName string, commandName } errgroup.Go(func() error { - return client.plugin.Do(ctx, commandName, args) + return client.plugin.Do(ctx, &DoCommand{ + CommandName: commandName, + Args: args, + }) }) if err := errgroup.Wait(); err != nil { diff --git a/pkg/register/plugin_server.go b/pkg/register/plugin_server.go index 01d9fdc..868a873 100644 --- a/pkg/register/plugin_server.go +++ b/pkg/register/plugin_server.go @@ -9,7 +9,7 @@ type PluginServer struct { Impl Plugin } -func (ps *PluginServer) Do(args *DoRequest, resp *string) error { +func (ps *PluginServer) Do(args *DoCommand, resp *string) error { //rawReq, ok := args.(string) //if !ok { // return errors.New("args is not a string") @@ -20,7 +20,7 @@ func (ps *PluginServer) Do(args *DoRequest, resp *string) error { // return err //} - if err := ps.Impl.Do(context.Background(), args.CommandName, args.Args); err != nil { + if err := ps.Impl.Do(context.Background(), args); err != nil { return err } *resp = ""