mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-09-20 04:36:09 +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.
38 lines
828 B
Go
38 lines
828 B
Go
package driver
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/OpenListTeam/OpenList/v5/proto/driver"
|
|
"github.com/hashicorp/go-plugin"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
func GetHandshakeConfig() plugin.HandshakeConfig {
|
|
return plugin.HandshakeConfig{
|
|
ProtocolVersion: 2,
|
|
MagicCookieKey: "OpenListTeam",
|
|
MagicCookieValue: "openlist",
|
|
}
|
|
}
|
|
|
|
type PluginIF interface {
|
|
Config(ctx context.Context) (Config, error)
|
|
}
|
|
|
|
type Plugin struct {
|
|
plugin.Plugin
|
|
Impl PluginIF
|
|
}
|
|
|
|
func (p *Plugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
|
|
driver.RegisterDriverServer(s, &GRPCServer{Impl: p.Impl})
|
|
return nil
|
|
}
|
|
|
|
func (p *Plugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (any, error) {
|
|
return &GRPCClient{client: driver.NewDriverClient(c)}, nil
|
|
}
|
|
|
|
var _ plugin.GRPCPlugin = (*Plugin)(nil)
|