apiv1

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package apiv1 implements the bridge between a extension and go-plugin providing most of the implementation for the extension if it's written in Go.

Index

Constants

View Source
const (
	// Version that this extension API implements
	Version = 1

	// Name is the plugin name that is served by go-plugin
	Name = "extension"

	// CookieKey is a basic UX feature for ensuring that
	// we execute a valid stencil plugin. This is exported
	// for ease of consumption by extensions.
	CookieKey = "STENCIL_PLUGIN"

	// CookieValue is the expected value for our CookieKey to
	// return.
	CookieValue = "はじめまして"
)

This block contains the constants for the go-plugin implementation.

Variables

This section is empty.

Functions

func NewExtensionImplementation

func NewExtensionImplementation(impl Implementation, log logrus.FieldLogger) error

NewExtensionImplementation implements a new extension and starts serving it.

func NewHandshake

func NewHandshake() plugin.HandshakeConfig

NewHandshake returns a plugin.HandshakeConfig for this extension api version.

Types

type Config

type Config struct{}

Config is configuration returned by an extension to the extension host.

type ExtensionPlugin

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

ExtensionPlugin is the high level plugin used by go-plugin it stores both the server and client implementation

func (*ExtensionPlugin) Client

func (p *ExtensionPlugin) Client(_ *plugin.MuxBroker, c *rpc.Client) (interface{}, error)

Client serves a Implementation over net/rpc

func (*ExtensionPlugin) Server

func (p *ExtensionPlugin) Server(*plugin.MuxBroker) (interface{}, error)

Server serves a implementationTransport over net/rpc

type Implementation

type Implementation interface {
	// GetConfig returns the configuration of this extension.
	GetConfig() (*Config, error)

	// GetTemplateFunctions returns all go-template functions this ext
	// implements, when a function is called, it's transparently passed over to
	// the actual extension and called there instead, its output being
	// returned.
	GetTemplateFunctions() ([]*TemplateFunction, error)

	// ExecuteTemplateFunction executes a provided template function
	// and returns its response.
	ExecuteTemplateFunction(t *TemplateFunctionExec) (interface{}, error)
}

Implementation is a plugin implementation

func NewExtensionClient

func NewExtensionClient(ctx context.Context, extPath string, log logrus.FieldLogger) (Implementation, func() error, error)

NewExtensionClient creates a new Implementation from a plugin

type TemplateFunction

type TemplateFunction struct {
	// Name of the template function, will be registered as:
	//  extensions.<extensionLowerName>.<name>
	Name string

	// NumberOfArguments is the number of arguments that the
	// template function takes.
	NumberOfArguments int
}

TemplateFunction is a request to create a new template function.

type TemplateFunctionExec

type TemplateFunctionExec struct {
	// Name is the name of the template function to execute.
	Name string

	// Arguments are the arbitrary arguments that were passed to this function
	Arguments []interface{}
}

TemplateFunctionExec executes a template function

Jump to

Keyboard shortcuts

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