WIP
This commit is contained in:
parent
d01dff5774
commit
12880e9ab3
@ -16,9 +16,14 @@ type About struct {
|
|||||||
Commands []*AboutCommand `json:"commands"`
|
Commands []*AboutCommand `json:"commands"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DoCommand struct {
|
||||||
|
CommandName string `json:"commandName"`
|
||||||
|
Args map[string]string `json:"args"`
|
||||||
|
}
|
||||||
|
|
||||||
type Plugin interface {
|
type Plugin interface {
|
||||||
About(ctx context.Context) (*About, error)
|
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"
|
const PluginKey = "plugin"
|
||||||
|
@ -10,22 +10,9 @@ type PluginClient struct {
|
|||||||
client *rpc.Client
|
client *rpc.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
type DoRequest struct {
|
|
||||||
CommandName string `json:"commandName"`
|
|
||||||
Args map[string]string `json:"args"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do implements Plugin
|
// Do implements Plugin
|
||||||
func (pc *PluginClient) Do(ctx context.Context, commandName string, args map[string]string) error {
|
func (pc *PluginClient) Do(ctx context.Context, cmd *DoCommand) error {
|
||||||
req := &DoRequest{
|
err := pc.client.Call("Plugin.Do", cmd, new(string))
|
||||||
CommandName: commandName,
|
|
||||||
Args: args,
|
|
||||||
}
|
|
||||||
//doReq, err := json.Marshal(req)
|
|
||||||
//if err != nil {
|
|
||||||
// return err
|
|
||||||
//}
|
|
||||||
err := pc.client.Call("Plugin.Do", req, new(any))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,10 @@ func (pr *PluginRegister) Do(ctx context.Context, clientName string, commandName
|
|||||||
}
|
}
|
||||||
|
|
||||||
errgroup.Go(func() error {
|
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 {
|
if err := errgroup.Wait(); err != nil {
|
||||||
|
@ -9,7 +9,7 @@ type PluginServer struct {
|
|||||||
Impl Plugin
|
Impl Plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ps *PluginServer) Do(args *DoRequest, resp *string) error {
|
func (ps *PluginServer) Do(args *DoCommand, resp *string) error {
|
||||||
//rawReq, ok := args.(string)
|
//rawReq, ok := args.(string)
|
||||||
//if !ok {
|
//if !ok {
|
||||||
// return errors.New("args is not a string")
|
// return errors.New("args is not a string")
|
||||||
@ -20,7 +20,7 @@ func (ps *PluginServer) Do(args *DoRequest, resp *string) error {
|
|||||||
// return err
|
// 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
|
return err
|
||||||
}
|
}
|
||||||
*resp = ""
|
*resp = ""
|
||||||
|
Loading…
Reference in New Issue
Block a user