mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-09-19 20:26:26 +08:00

- Added driver initialization for gRPC plugins in internal/bootstrap/driver.go. - Introduced configuration structures and protobuf definitions for driver plugins in proto/driver/config.proto and proto/driver/driver.proto. - Implemented gRPC server and client interfaces for driver plugins in shared/driver/grpc.go. - Created common response handling utilities in server/common/common.go and server/common/resp.go. - Developed plugin registration endpoint in server/handles/plugin.go. - Added test cases for plugin functionality in shared/driver/plugin_test.go. - Defined plugin reattachment configuration model in shared/model/plugin.go.
42 lines
896 B
Go
42 lines
896 B
Go
package driver
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/OpenListTeam/OpenList/v5/proto/driver"
|
|
"google.golang.org/protobuf/types/known/emptypb"
|
|
)
|
|
|
|
type GRPCServer struct {
|
|
Impl PluginIF
|
|
}
|
|
type GRPCClient struct {
|
|
client driver.DriverClient
|
|
}
|
|
|
|
func (s *GRPCServer) Config(ctx context.Context, in *emptypb.Empty) (*driver.Config, error) {
|
|
config, err := s.Impl.Config(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &driver.Config{
|
|
Name: config.Name,
|
|
Version: config.Version,
|
|
DefaultRoot: config.DefaultRoot,
|
|
}, nil
|
|
}
|
|
func (p *GRPCClient) Config(ctx context.Context) (Config, error) {
|
|
resp, err := p.client.Config(ctx, &emptypb.Empty{})
|
|
if err != nil {
|
|
return Config{}, err
|
|
}
|
|
return Config{
|
|
Name: resp.Name,
|
|
Version: resp.Version,
|
|
DefaultRoot: resp.DefaultRoot,
|
|
}, nil
|
|
}
|
|
|
|
var _ driver.DriverServer = (*GRPCServer)(nil)
|
|
var _ PluginIF = (*GRPCClient)(nil)
|