feat: support switch hashicorp plugin with environment HRP_PLUGIN_TYPE

This commit is contained in:
debugtalk
2022-03-04 20:34:24 +08:00
parent c27224a452
commit ea89a0b6a9
8 changed files with 73 additions and 21 deletions

View File

@@ -51,8 +51,8 @@ func Register(funcName string, fn interface{}) {
functions[funcName] = reflect.ValueOf(fn)
}
// Serve starts a plugin server process in RPC mode.
func ServeRPC() {
// serveRPC starts a plugin server process in RPC mode.
func serveRPC() {
log.Info().Msg("start plugin server in RPC mode")
funcPlugin := &functionPlugin{
logger: hclog.New(&hclog.LoggerOptions{
@@ -72,8 +72,8 @@ func ServeRPC() {
})
}
// Serve starts a plugin server process in gRPC mode.
func ServeGRPC() {
// serveGRPC starts a plugin server process in gRPC mode.
func serveGRPC() {
log.Info().Msg("start plugin server in gRPC mode")
funcPlugin := &functionPlugin{
logger: hclog.New(&hclog.LoggerOptions{
@@ -95,4 +95,11 @@ func ServeGRPC() {
}
// default to run plugin in gRPC mode
var Serve = ServeGRPC
func Serve() {
if pluginInternal.IsRPCPluginType() {
serveRPC()
} else {
// default
serveGRPC()
}
}