char/pkg/register/plugin_client.go

40 lines
653 B
Go
Raw Normal View History

2022-11-01 14:26:54 +01:00
package register
import (
2022-11-01 21:15:32 +01:00
"context"
"encoding/json"
2022-11-01 14:26:54 +01:00
"net/rpc"
)
type PluginClient struct {
client *rpc.Client
}
2022-11-05 23:05:41 +01:00
// Do implements Plugin
2022-11-05 23:19:09 +01:00
func (pc *PluginClient) Do(ctx context.Context, cmd *DoCommand) error {
err := pc.client.Call("Plugin.Do", cmd, new(string))
2022-11-05 23:05:41 +01:00
if err != nil {
return err
}
return nil
}
2022-11-01 14:26:54 +01:00
var _ Plugin = &PluginClient{}
2022-11-01 21:15:32 +01:00
func (pc *PluginClient) About(ctx context.Context) (*About, error) {
2022-11-01 14:26:54 +01:00
var resp string
err := pc.client.Call("Plugin.About", new(any), &resp)
if err != nil {
2022-11-01 21:15:32 +01:00
return nil, err
2022-11-01 14:26:54 +01:00
}
2022-11-01 21:15:32 +01:00
var about About
err = json.Unmarshal([]byte(resp), &about)
if err != nil {
return nil, err
}
return &about, nil
2022-11-01 14:26:54 +01:00
}