2022-11-01 14:26:54 +01:00
|
|
|
package register
|
|
|
|
|
2022-11-01 21:15:32 +01:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
2022-11-05 23:11:08 +01:00
|
|
|
"errors"
|
2022-11-01 21:15:32 +01:00
|
|
|
)
|
|
|
|
|
2022-11-01 14:26:54 +01:00
|
|
|
type PluginServer struct {
|
|
|
|
Impl Plugin
|
|
|
|
}
|
|
|
|
|
2022-11-05 23:11:08 +01:00
|
|
|
func (ps *PluginServer) Do(args any, resp *string) error {
|
|
|
|
rawReq, ok := args.(string)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("args is not a string")
|
|
|
|
}
|
|
|
|
|
2022-11-05 23:05:41 +01:00
|
|
|
var doReq DoRequest
|
2022-11-05 23:11:08 +01:00
|
|
|
if err := json.Unmarshal([]byte(rawReq), &doReq); err != nil {
|
2022-11-05 23:05:41 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := ps.Impl.Do(context.Background(), doReq.CommandName, doReq.Args); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-11-01 14:26:54 +01:00
|
|
|
func (ps *PluginServer) About(args any, resp *string) error {
|
2022-11-01 21:15:32 +01:00
|
|
|
r, err := ps.Impl.About(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
respB, err := json.Marshal(r)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
*resp = string(respB)
|
2022-11-01 14:26:54 +01:00
|
|
|
return nil
|
|
|
|
}
|