Replace manual HTTP/JSON RPC implementation with generated gRPC/Connect client, providing type-safe plugin communication. Code Generation: - Generate plugin.pb.go and pluginv1connect/plugin.connect.go from plugin.proto - Add generate-plugin-proto Makefile target - Delete hand-written types.go (replaced by generated code) ExternalPluginManager Refactoring: - Replace httpClient with pluginv1connect.PluginServiceClient - Use h2c (cleartext HTTP/2) transport for gRPC without TLS - Replace all manual callRPC/callRPCWithContext calls with typed Connect methods - Remove JSON serialization/deserialization code - Simplify error handling with native gRPC status codes Benefits: - Type safety: compile-time verification of request/response types - Protocol compatibility: standard gRPC wire format - Reduced code: ~100 lines of manual RPC code removed - Better errors: structured gRPC status codes instead of string parsing - Matches existing Actions runner pattern (Connect RPC over HTTP/2) This completes the plugin framework migration to production-grade RPC transport.
265 lines
14 KiB
Go
265 lines
14 KiB
Go
// Code generated by protoc-gen-connect-go. DO NOT EDIT.
|
|
//
|
|
// Source: modules/plugins/pluginv1/plugin.proto
|
|
|
|
package pluginv1connect
|
|
|
|
import (
|
|
pluginv1 "code.gitcaddy.com/server/v3/modules/plugins/pluginv1"
|
|
connect "connectrpc.com/connect"
|
|
context "context"
|
|
errors "errors"
|
|
http "net/http"
|
|
strings "strings"
|
|
)
|
|
|
|
// This is a compile-time assertion to ensure that this generated file and the connect package are
|
|
// compatible. If you get a compiler error that this constant is not defined, this code was
|
|
// generated with a version of connect newer than the one compiled into your binary. You can fix the
|
|
// problem by either regenerating this code with an older version of connect or updating the connect
|
|
// version compiled into your binary.
|
|
const _ = connect.IsAtLeastVersion1_13_0
|
|
|
|
const (
|
|
// PluginServiceName is the fully-qualified name of the PluginService service.
|
|
PluginServiceName = "plugin.v1.PluginService"
|
|
)
|
|
|
|
// These constants are the fully-qualified names of the RPCs defined in this package. They're
|
|
// exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route.
|
|
//
|
|
// Note that these are different from the fully-qualified method names used by
|
|
// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to
|
|
// reflection-formatted method names, remove the leading slash and convert the remaining slash to a
|
|
// period.
|
|
const (
|
|
// PluginServiceInitializeProcedure is the fully-qualified name of the PluginService's Initialize
|
|
// RPC.
|
|
PluginServiceInitializeProcedure = "/plugin.v1.PluginService/Initialize"
|
|
// PluginServiceShutdownProcedure is the fully-qualified name of the PluginService's Shutdown RPC.
|
|
PluginServiceShutdownProcedure = "/plugin.v1.PluginService/Shutdown"
|
|
// PluginServiceHealthCheckProcedure is the fully-qualified name of the PluginService's HealthCheck
|
|
// RPC.
|
|
PluginServiceHealthCheckProcedure = "/plugin.v1.PluginService/HealthCheck"
|
|
// PluginServiceGetManifestProcedure is the fully-qualified name of the PluginService's GetManifest
|
|
// RPC.
|
|
PluginServiceGetManifestProcedure = "/plugin.v1.PluginService/GetManifest"
|
|
// PluginServiceOnEventProcedure is the fully-qualified name of the PluginService's OnEvent RPC.
|
|
PluginServiceOnEventProcedure = "/plugin.v1.PluginService/OnEvent"
|
|
// PluginServiceHandleHTTPProcedure is the fully-qualified name of the PluginService's HandleHTTP
|
|
// RPC.
|
|
PluginServiceHandleHTTPProcedure = "/plugin.v1.PluginService/HandleHTTP"
|
|
)
|
|
|
|
// PluginServiceClient is a client for the plugin.v1.PluginService service.
|
|
type PluginServiceClient interface {
|
|
// Initialize is called when the server starts or the plugin is loaded
|
|
Initialize(context.Context, *connect.Request[pluginv1.InitializeRequest]) (*connect.Response[pluginv1.InitializeResponse], error)
|
|
// Shutdown is called when the server is shutting down
|
|
Shutdown(context.Context, *connect.Request[pluginv1.ShutdownRequest]) (*connect.Response[pluginv1.ShutdownResponse], error)
|
|
// HealthCheck checks if the plugin is healthy
|
|
HealthCheck(context.Context, *connect.Request[pluginv1.HealthCheckRequest]) (*connect.Response[pluginv1.HealthCheckResponse], error)
|
|
// GetManifest returns the plugin's manifest describing its capabilities
|
|
GetManifest(context.Context, *connect.Request[pluginv1.GetManifestRequest]) (*connect.Response[pluginv1.PluginManifest], error)
|
|
// OnEvent is called when an event the plugin is subscribed to occurs
|
|
OnEvent(context.Context, *connect.Request[pluginv1.PluginEvent]) (*connect.Response[pluginv1.EventResponse], error)
|
|
// HandleHTTP proxies an HTTP request to the plugin
|
|
HandleHTTP(context.Context, *connect.Request[pluginv1.HTTPRequest]) (*connect.Response[pluginv1.HTTPResponse], error)
|
|
}
|
|
|
|
// NewPluginServiceClient constructs a client for the plugin.v1.PluginService service. By default,
|
|
// it uses the Connect protocol with the binary Protobuf Codec, asks for gzipped responses, and
|
|
// sends uncompressed requests. To use the gRPC or gRPC-Web protocols, supply the connect.WithGRPC()
|
|
// or connect.WithGRPCWeb() options.
|
|
//
|
|
// The URL supplied here should be the base URL for the Connect or gRPC server (for example,
|
|
// http://api.acme.com or https://acme.com/grpc).
|
|
func NewPluginServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) PluginServiceClient {
|
|
baseURL = strings.TrimRight(baseURL, "/")
|
|
pluginServiceMethods := pluginv1.File_modules_plugins_pluginv1_plugin_proto.Services().ByName("PluginService").Methods()
|
|
return &pluginServiceClient{
|
|
initialize: connect.NewClient[pluginv1.InitializeRequest, pluginv1.InitializeResponse](
|
|
httpClient,
|
|
baseURL+PluginServiceInitializeProcedure,
|
|
connect.WithSchema(pluginServiceMethods.ByName("Initialize")),
|
|
connect.WithClientOptions(opts...),
|
|
),
|
|
shutdown: connect.NewClient[pluginv1.ShutdownRequest, pluginv1.ShutdownResponse](
|
|
httpClient,
|
|
baseURL+PluginServiceShutdownProcedure,
|
|
connect.WithSchema(pluginServiceMethods.ByName("Shutdown")),
|
|
connect.WithClientOptions(opts...),
|
|
),
|
|
healthCheck: connect.NewClient[pluginv1.HealthCheckRequest, pluginv1.HealthCheckResponse](
|
|
httpClient,
|
|
baseURL+PluginServiceHealthCheckProcedure,
|
|
connect.WithSchema(pluginServiceMethods.ByName("HealthCheck")),
|
|
connect.WithClientOptions(opts...),
|
|
),
|
|
getManifest: connect.NewClient[pluginv1.GetManifestRequest, pluginv1.PluginManifest](
|
|
httpClient,
|
|
baseURL+PluginServiceGetManifestProcedure,
|
|
connect.WithSchema(pluginServiceMethods.ByName("GetManifest")),
|
|
connect.WithClientOptions(opts...),
|
|
),
|
|
onEvent: connect.NewClient[pluginv1.PluginEvent, pluginv1.EventResponse](
|
|
httpClient,
|
|
baseURL+PluginServiceOnEventProcedure,
|
|
connect.WithSchema(pluginServiceMethods.ByName("OnEvent")),
|
|
connect.WithClientOptions(opts...),
|
|
),
|
|
handleHTTP: connect.NewClient[pluginv1.HTTPRequest, pluginv1.HTTPResponse](
|
|
httpClient,
|
|
baseURL+PluginServiceHandleHTTPProcedure,
|
|
connect.WithSchema(pluginServiceMethods.ByName("HandleHTTP")),
|
|
connect.WithClientOptions(opts...),
|
|
),
|
|
}
|
|
}
|
|
|
|
// pluginServiceClient implements PluginServiceClient.
|
|
type pluginServiceClient struct {
|
|
initialize *connect.Client[pluginv1.InitializeRequest, pluginv1.InitializeResponse]
|
|
shutdown *connect.Client[pluginv1.ShutdownRequest, pluginv1.ShutdownResponse]
|
|
healthCheck *connect.Client[pluginv1.HealthCheckRequest, pluginv1.HealthCheckResponse]
|
|
getManifest *connect.Client[pluginv1.GetManifestRequest, pluginv1.PluginManifest]
|
|
onEvent *connect.Client[pluginv1.PluginEvent, pluginv1.EventResponse]
|
|
handleHTTP *connect.Client[pluginv1.HTTPRequest, pluginv1.HTTPResponse]
|
|
}
|
|
|
|
// Initialize calls plugin.v1.PluginService.Initialize.
|
|
func (c *pluginServiceClient) Initialize(ctx context.Context, req *connect.Request[pluginv1.InitializeRequest]) (*connect.Response[pluginv1.InitializeResponse], error) {
|
|
return c.initialize.CallUnary(ctx, req)
|
|
}
|
|
|
|
// Shutdown calls plugin.v1.PluginService.Shutdown.
|
|
func (c *pluginServiceClient) Shutdown(ctx context.Context, req *connect.Request[pluginv1.ShutdownRequest]) (*connect.Response[pluginv1.ShutdownResponse], error) {
|
|
return c.shutdown.CallUnary(ctx, req)
|
|
}
|
|
|
|
// HealthCheck calls plugin.v1.PluginService.HealthCheck.
|
|
func (c *pluginServiceClient) HealthCheck(ctx context.Context, req *connect.Request[pluginv1.HealthCheckRequest]) (*connect.Response[pluginv1.HealthCheckResponse], error) {
|
|
return c.healthCheck.CallUnary(ctx, req)
|
|
}
|
|
|
|
// GetManifest calls plugin.v1.PluginService.GetManifest.
|
|
func (c *pluginServiceClient) GetManifest(ctx context.Context, req *connect.Request[pluginv1.GetManifestRequest]) (*connect.Response[pluginv1.PluginManifest], error) {
|
|
return c.getManifest.CallUnary(ctx, req)
|
|
}
|
|
|
|
// OnEvent calls plugin.v1.PluginService.OnEvent.
|
|
func (c *pluginServiceClient) OnEvent(ctx context.Context, req *connect.Request[pluginv1.PluginEvent]) (*connect.Response[pluginv1.EventResponse], error) {
|
|
return c.onEvent.CallUnary(ctx, req)
|
|
}
|
|
|
|
// HandleHTTP calls plugin.v1.PluginService.HandleHTTP.
|
|
func (c *pluginServiceClient) HandleHTTP(ctx context.Context, req *connect.Request[pluginv1.HTTPRequest]) (*connect.Response[pluginv1.HTTPResponse], error) {
|
|
return c.handleHTTP.CallUnary(ctx, req)
|
|
}
|
|
|
|
// PluginServiceHandler is an implementation of the plugin.v1.PluginService service.
|
|
type PluginServiceHandler interface {
|
|
// Initialize is called when the server starts or the plugin is loaded
|
|
Initialize(context.Context, *connect.Request[pluginv1.InitializeRequest]) (*connect.Response[pluginv1.InitializeResponse], error)
|
|
// Shutdown is called when the server is shutting down
|
|
Shutdown(context.Context, *connect.Request[pluginv1.ShutdownRequest]) (*connect.Response[pluginv1.ShutdownResponse], error)
|
|
// HealthCheck checks if the plugin is healthy
|
|
HealthCheck(context.Context, *connect.Request[pluginv1.HealthCheckRequest]) (*connect.Response[pluginv1.HealthCheckResponse], error)
|
|
// GetManifest returns the plugin's manifest describing its capabilities
|
|
GetManifest(context.Context, *connect.Request[pluginv1.GetManifestRequest]) (*connect.Response[pluginv1.PluginManifest], error)
|
|
// OnEvent is called when an event the plugin is subscribed to occurs
|
|
OnEvent(context.Context, *connect.Request[pluginv1.PluginEvent]) (*connect.Response[pluginv1.EventResponse], error)
|
|
// HandleHTTP proxies an HTTP request to the plugin
|
|
HandleHTTP(context.Context, *connect.Request[pluginv1.HTTPRequest]) (*connect.Response[pluginv1.HTTPResponse], error)
|
|
}
|
|
|
|
// NewPluginServiceHandler builds an HTTP handler from the service implementation. It returns the
|
|
// path on which to mount the handler and the handler itself.
|
|
//
|
|
// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf
|
|
// and JSON codecs. They also support gzip compression.
|
|
func NewPluginServiceHandler(svc PluginServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) {
|
|
pluginServiceMethods := pluginv1.File_modules_plugins_pluginv1_plugin_proto.Services().ByName("PluginService").Methods()
|
|
pluginServiceInitializeHandler := connect.NewUnaryHandler(
|
|
PluginServiceInitializeProcedure,
|
|
svc.Initialize,
|
|
connect.WithSchema(pluginServiceMethods.ByName("Initialize")),
|
|
connect.WithHandlerOptions(opts...),
|
|
)
|
|
pluginServiceShutdownHandler := connect.NewUnaryHandler(
|
|
PluginServiceShutdownProcedure,
|
|
svc.Shutdown,
|
|
connect.WithSchema(pluginServiceMethods.ByName("Shutdown")),
|
|
connect.WithHandlerOptions(opts...),
|
|
)
|
|
pluginServiceHealthCheckHandler := connect.NewUnaryHandler(
|
|
PluginServiceHealthCheckProcedure,
|
|
svc.HealthCheck,
|
|
connect.WithSchema(pluginServiceMethods.ByName("HealthCheck")),
|
|
connect.WithHandlerOptions(opts...),
|
|
)
|
|
pluginServiceGetManifestHandler := connect.NewUnaryHandler(
|
|
PluginServiceGetManifestProcedure,
|
|
svc.GetManifest,
|
|
connect.WithSchema(pluginServiceMethods.ByName("GetManifest")),
|
|
connect.WithHandlerOptions(opts...),
|
|
)
|
|
pluginServiceOnEventHandler := connect.NewUnaryHandler(
|
|
PluginServiceOnEventProcedure,
|
|
svc.OnEvent,
|
|
connect.WithSchema(pluginServiceMethods.ByName("OnEvent")),
|
|
connect.WithHandlerOptions(opts...),
|
|
)
|
|
pluginServiceHandleHTTPHandler := connect.NewUnaryHandler(
|
|
PluginServiceHandleHTTPProcedure,
|
|
svc.HandleHTTP,
|
|
connect.WithSchema(pluginServiceMethods.ByName("HandleHTTP")),
|
|
connect.WithHandlerOptions(opts...),
|
|
)
|
|
return "/plugin.v1.PluginService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
switch r.URL.Path {
|
|
case PluginServiceInitializeProcedure:
|
|
pluginServiceInitializeHandler.ServeHTTP(w, r)
|
|
case PluginServiceShutdownProcedure:
|
|
pluginServiceShutdownHandler.ServeHTTP(w, r)
|
|
case PluginServiceHealthCheckProcedure:
|
|
pluginServiceHealthCheckHandler.ServeHTTP(w, r)
|
|
case PluginServiceGetManifestProcedure:
|
|
pluginServiceGetManifestHandler.ServeHTTP(w, r)
|
|
case PluginServiceOnEventProcedure:
|
|
pluginServiceOnEventHandler.ServeHTTP(w, r)
|
|
case PluginServiceHandleHTTPProcedure:
|
|
pluginServiceHandleHTTPHandler.ServeHTTP(w, r)
|
|
default:
|
|
http.NotFound(w, r)
|
|
}
|
|
})
|
|
}
|
|
|
|
// UnimplementedPluginServiceHandler returns CodeUnimplemented from all methods.
|
|
type UnimplementedPluginServiceHandler struct{}
|
|
|
|
func (UnimplementedPluginServiceHandler) Initialize(context.Context, *connect.Request[pluginv1.InitializeRequest]) (*connect.Response[pluginv1.InitializeResponse], error) {
|
|
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("plugin.v1.PluginService.Initialize is not implemented"))
|
|
}
|
|
|
|
func (UnimplementedPluginServiceHandler) Shutdown(context.Context, *connect.Request[pluginv1.ShutdownRequest]) (*connect.Response[pluginv1.ShutdownResponse], error) {
|
|
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("plugin.v1.PluginService.Shutdown is not implemented"))
|
|
}
|
|
|
|
func (UnimplementedPluginServiceHandler) HealthCheck(context.Context, *connect.Request[pluginv1.HealthCheckRequest]) (*connect.Response[pluginv1.HealthCheckResponse], error) {
|
|
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("plugin.v1.PluginService.HealthCheck is not implemented"))
|
|
}
|
|
|
|
func (UnimplementedPluginServiceHandler) GetManifest(context.Context, *connect.Request[pluginv1.GetManifestRequest]) (*connect.Response[pluginv1.PluginManifest], error) {
|
|
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("plugin.v1.PluginService.GetManifest is not implemented"))
|
|
}
|
|
|
|
func (UnimplementedPluginServiceHandler) OnEvent(context.Context, *connect.Request[pluginv1.PluginEvent]) (*connect.Response[pluginv1.EventResponse], error) {
|
|
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("plugin.v1.PluginService.OnEvent is not implemented"))
|
|
}
|
|
|
|
func (UnimplementedPluginServiceHandler) HandleHTTP(context.Context, *connect.Request[pluginv1.HTTPRequest]) (*connect.Response[pluginv1.HTTPResponse], error) {
|
|
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("plugin.v1.PluginService.HandleHTTP is not implemented"))
|
|
}
|