plugin/shared/plugin.go

31 lines
628 B
Go
Raw Normal View History

2024-08-30 18:02:15 +08:00
package shared
import (
"github.com/hashicorp/go-plugin"
)
type Plugin struct {
Tag string
P PluginService
}
func NewPlugin(p PluginService, tag string) *Plugin {
return &Plugin{P: p, Tag: tag}
}
func PluginSet(opts ...*Plugin) plugin.PluginSet {
plugins := make(map[string]plugin.Plugin, len(opts))
for _, opt := range opts {
plugins[opt.Tag] = &GRPCPlugin{Impl: opt.P}
}
return plugins
}
func HandshakeConfig(version uint, cookieKey, cookieValue string) plugin.HandshakeConfig {
return plugin.HandshakeConfig{
ProtocolVersion: version,
MagicCookieKey: cookieKey,
MagicCookieValue: cookieValue,
}
}