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.
Package apiv1 implements the extension API for stencil
Index ¶
Constants ¶
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) 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 {
// Name is the name of this extension, used for template
// function naming
Name string
}
Config is configuration returned by an extension to the extension host.
type ExtensionPlugin ¶
type ExtensionPlugin struct {
// Impl is the real implementation for this extension
Impl Implementation
}
ExtensionPlugin is the high level plugin used by go-plugin it stores both the server and client implementation
type ExtensionPluginClient ¶
type ExtensionPluginClient struct {
// contains filtered or unexported fields
}
ExtensionPluginClient implements a client that communicates over RPC
func (*ExtensionPluginClient) ExecuteTemplateFunction ¶
func (g *ExtensionPluginClient) ExecuteTemplateFunction(t *TemplateFunctionExec) (interface{}, error)
ExecuteTemplateFunction exectues a template function for this extension
func (*ExtensionPluginClient) GetConfig ¶
func (g *ExtensionPluginClient) GetConfig() (*Config, error)
GetConfig returns the config for the extension
func (*ExtensionPluginClient) GetTemplateFunctions ¶
func (g *ExtensionPluginClient) GetTemplateFunctions() ([]*TemplateFunction, error)
GetTemplateFunctions returns the template functions for this extension
type ExtensionPluginServer ¶
type ExtensionPluginServer struct {
Impl Implementation
}
ExtensionPluginServer implements a rpc compliant server
func (*ExtensionPluginServer) ExecuteTemplateFunction ¶
func (s *ExtensionPluginServer) ExecuteTemplateFunction(t *TemplateFunctionExec, resp *interface{}) error
ExecuteTemplateFunction executes a template function for this extension
func (*ExtensionPluginServer) GetConfig ¶
func (s *ExtensionPluginServer) GetConfig(args interface{}, resp **Config) error
GetConfig returns the config for this extension
func (*ExtensionPluginServer) GetTemplateFunctions ¶
func (s *ExtensionPluginServer) GetTemplateFunctions(args interface{}, resp *[]*TemplateFunction) error
GetTemplateFunctions returns the template functions for this extension
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 the extension api that is implemented by all extensions.
type TemplateFunction ¶
type TemplateFunction struct {
// Name of the template function, will be registered as:
// extensions.<extensionLowerName>.<name>
Name string
// ArgumentTypes are the argument types that this function
// expects. They should be serializable via gob.
ArgumentTypes []interface{}
// ReturnType is the return type for this function, note that
// the signature is always (type, error) and that error is already
// included in the function signature.
ReturnType interface{}
}
TemplateFunction is a request to create a new template function.
type TemplateFunctionExec ¶
type TemplateFunctionExec struct {
// Name is the name of this go-template function. It will be prefixed with the
// following format: extensions.<name>.<templateName>
Name string
// Arguments are the arbitrary arguments that were passed to this function
Arguments []interface{}
}
TemplateFunctionExec executes a template function