Documentation ¶
Overview ¶
Package binarywrapper is a utility package that makes wrapping binaries a little easier as it aims to provide a common structure to use for converting binaries into plugins. Along the way it allows for some setup tasks, validation, and execution.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrValidation is returned if the plugin fails validation. ErrValidation = errors.New("plugin failed validation") // ErrSetup is returned if the plugin fails to setup. ErrSetup = errors.New("plugin failed setup") // ErrUnknownExecStyle is returned when a plugin is configured with an unknown // execution style. Look at binarywrapper.ExecStyle for the available options. ErrUnknownExecStyle = errors.New("unknown ExecStyle, look at binarywrapper.ExecStyle for the available options") // ErrMissingBinary is returned when the binary referenced is not found. ErrMissingBinary = errors.New("missing binary") // ErrExec is returned for any generic execution based error. ErrExec = errors.New("execution error") )
Functions ¶
This section is empty.
Types ¶
type ExecStyle ¶
type ExecStyle int
ExecStyle defines the types of execution paradims exists for the plugin.
const ( // SyscallExec sets the execution style such that when the binary is finally called // the system turns over all processing and resources over to said binary without // the overhead of Go still being in the way. What this means in practice is that // you're at the whim of how the binary behaves for logging, output, etc. SyscallExec ExecStyle = iota // OSExecCommand sets the execution style such that when the binary is called it is // done using a subprocess command. The output of the command is captured when finished // and not streamed, so if you desire streaming based output you should use SyscallExec for now. OSExecCommand )
type Plugin ¶
type Plugin struct { ExecStyle PluginConfig }
Plugin holds the configuration required for a binarywrapper.Plugin to operate. We need a struct that implements the required binarywrapper.PluginConfig functions. It can also optionally set or override the execution style before the plugin is called.
func (*Plugin) Exec ¶
Exec will call the plugin Validate, Setup and Exec methods This uses syscall.Exec to take over the processing. What this means is whatever binary is defined in the plugin will take over execution and if there are no errors this is the end of the relevant go code and handling required for the plugin. Think of this like the binary taking the place of the go code if the binary is found.
type PluginConfig ¶
type PluginConfig interface { // Validate is responsible for checking all of the plugin's // configuration is valid before the plugin Setup() is executed. Validate() error // Setup is responsible to create all required files are in // place before any executable or shell actions are created. Setup() error // Binary should return the absolute path to the binary that should take // over when this plugin has been validated for execution. This should // not use any environmental variables like $HOME. Binary() string // Arguments should return the arguments to the binary when this plugin is executed. // If these include environmental variables like $HOME they'll // be expanded before execution by the shell. Arguments() []string // Environment should return any additional environmental variables // to use for the binary when this plugin is executed. Environment() map[string]string }
PluginConfig holds the key methods required for a binarywrapper.Plugin to operate and enforces a common structure for wrapping binary plugins.