Files
2026-11-16 05:11:58 +11:00

41 lines
1.0 KiB
Go

package guard
import (
"context"
goplugin "github.com/hashicorp/go-plugin"
"google.golang.org/grpc"
guardv1 "github.com/samcharles93/archipelago/sdk/guard/v1"
)
const surface = "guard"
type plugin struct {
goplugin.NetRPCUnsupportedPlugin
impl guardv1.GuardServiceServer
}
func (p *plugin) GRPCServer(_ *goplugin.GRPCBroker, s *grpc.Server) error {
guardv1.RegisterGuardServiceServer(s, p.impl)
return nil
}
func (*plugin) GRPCClient(context.Context, *goplugin.GRPCBroker, *grpc.ClientConn) (any, error) {
return nil, nil
}
// Serve runs the guard build returns as the extension process. build is called
// on every Configure. Serve returns when archie-core stops the extension.
func Serve(build func(Config) (Guard, error)) {
goplugin.Serve(&goplugin.ServeConfig{
HandshakeConfig: goplugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "ARCHIE_EXTENSION",
MagicCookieValue: "archie",
},
Plugins: goplugin.PluginSet{surface: &plugin{impl: &server{build: build}}},
GRPCServer: goplugin.DefaultGRPCServer,
})
}