grpc

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2022 License: Apache-2.0 Imports: 11 Imported by: 1

README

GRPC Plugin

Updating the Protocol

If you update the protocol buffers file, you can regenerate the file using the following command from this directory. You do not need to run this if you're just trying the example.

protoc -I proto/ proto/model.proto  --go_out=plugins=grpc:proto/

More

https://github.com/hashicorp/go-plugin/tree/master/examples/grpc

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Handshake = plugin.HandshakeConfig{

	ProtocolVersion:  1,
	MagicCookieKey:   "GOU_MODEL_PLUGIN",
	MagicCookieValue: "GOU VER0.6.0",
}

Handshake is a common handshake that is shared by plugin and host.

View Source
var PluginMap = map[string]plugin.Plugin{
	"model": &ModelGRPCPlugin{},
}

PluginMap is the map of plugins we can dispense.

Functions

func Serve added in v0.6.1

func Serve(model Model)

Serve GRPC Server

Types

type ClientGRPC

type ClientGRPC struct {
	// contains filtered or unexported fields
}

ClientGRPC is an implementation of KV that talks over RPC.

func (*ClientGRPC) Exec

func (m *ClientGRPC) Exec(name string, args ...interface{}) (*Response, error)

Exec execute the plugin model

type Level added in v0.6.1

type Level int32

Level represents a log level.

const (
	// NoLevel is a special level used to indicate that no level has been
	// set and allow for a default to be used.
	NoLevel Level = 0

	// Trace is the most verbose level. Intended to be used for the tracing
	// of actions in code, such as function enters/exits, etc.
	Trace Level = 1

	// Debug information for programmer lowlevel analysis.
	Debug Level = 2

	// Info information about steady state operations.
	Info Level = 3

	// Warn information about rare but handled events.
	Warn Level = 4

	// Error information about unrecoverable events.
	Error Level = 5

	// Off disables all logging output.
	Off Level = 6
)

type Model

type Model interface {
	Exec(name string, args ...interface{}) (*Response, error)
}

Model is the interface that we're exposing as a plugin.

type ModelGRPCPlugin

type ModelGRPCPlugin struct {
	// GRPCPlugin must still implement the Plugin interface
	plugin.Plugin
	// Concrete implementation, written in Go. This is only used for plugins
	// that are written in Go.
	Impl Model
}

ModelGRPCPlugin This is the implementation of plugin.Plugin so we can serve/consume this.

func (*ModelGRPCPlugin) GRPCClient

func (p *ModelGRPCPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error)

GRPCClient the GRPC client

func (*ModelGRPCPlugin) GRPCServer

func (p *ModelGRPCPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error

GRPCServer the GRPC Server

type Plugin added in v0.6.1

type Plugin struct {
	Logger hclog.Logger
}

Plugin Here is a real implementation of Pluine that writes to a local file with the key name and the contents are the value of the key.

func (*Plugin) SetLogger added in v0.6.1

func (plugin *Plugin) SetLogger(output io.Writer, level Level)

SetLogger set logger output

type Response

type Response struct {
	Bytes []byte
	Type  string
}

Response GRPC Response

func (Response) Array added in v0.6.1

func (res Response) Array() ([]interface{}, error)

Array cast to array | slice

func (Response) Bind

func (res Response) Bind(v interface{}) error

Bind bind struct

func (Response) Interface added in v0.6.1

func (res Response) Interface() (interface{}, error)

Interface bind struct

func (Response) Map

func (res Response) Map() (maps.MapStrAny, error)

Map cast to map

func (Response) MustArray added in v0.6.1

func (res Response) MustArray() []interface{}

MustArray cast to array | slice

func (Response) MustBind added in v0.6.1

func (res Response) MustBind(v interface{})

MustBind bind struct

func (Response) MustInterface added in v0.6.1

func (res Response) MustInterface() interface{}

MustInterface bind struct

func (Response) MustMap

func (res Response) MustMap() maps.MapStrAny

MustMap cast to map

func (Response) MustValue added in v0.6.1

func (res Response) MustValue() interface{}

MustValue get the response value

func (Response) Value added in v0.6.1

func (res Response) Value() (interface{}, error)

Value get the response value

type ServerGRPC

type ServerGRPC struct {
	// This is the real implementation
	Impl Model
}

ServerGRPC Here is the gRPC server that ClientGRPC talks to.

func (*ServerGRPC) Exec

func (m *ServerGRPC) Exec(ctx context.Context, req *proto.Request) (*proto.Response, error)

Exec ServerGet

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL