plugin

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 18 Imported by: 0

README

Plugin

Plugin is a simple package to build gRPC based plugins. This is heavily inspired by the go-plugin project.

Check the examples to learn more.

Documentation

Index

Constants

View Source
const (
	PLUGIN_DISCOVERY_ADDRESS = "PLUGIN_DISCOVERY_ADDRESS"
	PLUGIN_SOCKET_TYPE       = "PLUGIN_SOCKET_TYPE"
	PLUGIN_MIN_PORT          = "PLUGIN_MIN_PORT"
	PLUGIN_MAX_PORT          = "PLUGIN_MAX_PORT"
	MIN_PORT                 = 10000
	MAX_PORT                 = 15000

	SOCKET_TYPE_TCP  = "tcp"
	SOCKET_TYPE_UNIX = "unix"
)

Variables

This section is empty.

Functions

func DeserializeObject added in v0.2.0

func DeserializeObject(data []byte, typeName string) (interface{}, error)

DeserializeObject reconstructs an object from bytes

func Load

func Load(opt PluginLoadOptions, cs store.CatalogStore) (interface{}, error)

Load loads a plugin either from a remote address or a local process. If the address is provided, it connects to the remote plugin using gRPC. If not, it starts the plugin in a subprocess and returns the client.

func RegisterType added in v0.2.0

func RegisterType(value interface{})

RegisterType registers a type with the global registry

func SerializeObject added in v0.2.0

func SerializeObject(obj interface{}) ([]byte, string, error)

SerializeObject serializes an object to bytes

func Serve

func Serve(p Plugin, opt PluginServeOptions) error

Serve starts a gRPC server for the plugin and listens on the provided address. If host is empty, it binds to all interfaces but returns the first non-loopback local IP address for the client and discovery server.

Types

type Plugin

type Plugin interface {
	Client(*grpc.ClientConn) (interface{}, error)
	Server(*grpc.Server) error
}

type PluginLoadOptions

type PluginLoadOptions struct {
	Name    string
	Path    string
	Address string
	Plugin  Plugin
}

type PluginResponse

type PluginResponse struct {
	SocketType string `json:"socket_type"`
	Address    string `json:"address"`
}

type PluginServeOptions

type PluginServeOptions struct {
	Name string
	Host string
}

type TypeRegistry added in v0.2.0

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

TypeRegistry maintains a mapping of type names to their concrete types

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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