char/pkg/register/plugin_server.go

45 lines
725 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:19:09 +01:00
func (ps *PluginServer) Do(args *DoCommand, resp *string) error {
2022-11-05 23:16:20 +01:00
//rawReq, ok := args.(string)
//if !ok {
// return errors.New("args is not a string")
//}
2022-11-05 23:11:08 +01:00
2022-11-05 23:16:20 +01:00
//var doReq DoRequest
//if err := json.Unmarshal([]byte(rawReq), &doReq); err != nil {
// return err
//}
2022-11-05 23:05:41 +01:00
2022-11-05 23:19:09 +01:00
if err := ps.Impl.Do(context.Background(), args); err != nil {
2022-11-05 23:05:41 +01:00
return err
}
2022-11-05 23:16:20 +01:00
*resp = ""
2022-11-05 23:05:41 +01:00
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
}