char/pkg/register/plugin_server.go

39 lines
629 B
Go
Raw Normal View History

2022-11-01 14:26:54 +01:00
package register
2022-11-01 21:15:32 +01:00
import (
"context"
"encoding/json"
)
2022-11-01 14:26:54 +01:00
type PluginServer struct {
Impl Plugin
}
2022-11-05 23:09:16 +01:00
func (ps *PluginServer) Do(args string, resp *string) error {
2022-11-05 23:05:41 +01:00
var doReq DoRequest
2022-11-05 23:09:16 +01:00
if err := json.Unmarshal([]byte(args), &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
}