plugins

package
v0.0.0-...-69a7c56 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultCache = ".mirror"

Variables

View Source
var (
	ErrFindPackageFailed      = errors.New("An error occurred when loading plugin")
	ErrCopyingToCacheFailed   = errors.New("Failed to copy package to the cache")
	ErrSymbolGenerationFailed = errors.New("Failed to generate symbols")
	ErrBuildFailed            = errors.New("Failed to build the plugin")
	ErrSymbolLoadFailed       = errors.New("Failed to load symbols from the plugin")
)

Functions

func Build

func Build(pkg string, out string) (string, error)

Build builds the given package into plugin and saves it in current path under a random name .so, returning the name to the caller

func ChangePackage

func ChangePackage(pkgName, desiredPkgName string) error

ChangePackage changes the `package X` line of each file in the targeted package, changing its name to the desiredPkgName, running the `run` function and changing it back to the default

func CopyPackageToCache

func CopyPackageToCache(pkg *packages.Package, cacheDir string) (string, error)

CopyPackageToCache copies a given package into a given cache dir returning the cache dir subdirectory into which the package was copied

func FindPackage

func FindPackage(pkg string) (*packages.Package, error)

FindPackage returns names of go files in the targeted package

func GenerateSymbolsForModels

func GenerateSymbolsForModels(symbolNames []string, out string) ([]string, error)

GenerateSymbolsForModels generates symbols for all models, mutates the input symbols to be compatible with newly created symbols and writes a new file with these generated symbols

func LoadSymbols

func LoadSymbols(pluginPath string, symbols []string) ([]interface{}, error)

LoadSymbols accepts a plugin path and returns all symbols that were found in the given plugin. If * is provided as only value in `symbols`, all symbols from the given plugin will be returned

Types

type Loader

type Loader struct {
	// TargetPath is a relative path to the plugin that should be built
	TargetPath string

	// PreserveCache determines if the copied cached files should be preserved
	// at the end of the lifecycle
	PreserveCache bool

	// GenerateSymbols automatically generates symbols for desired types,
	// e.g. type User struct {} will have his var XUser User generated
	// in case it is passed into symbolNames for Load function
	GenerateSymbols bool

	// CacheDir can be used to override the default setting of the cache directory
	// if not set, this will default to the DefaultCache
	CacheDir string
}

Loader encapsulates full lifecycle of a plugin

func (*Loader) Load

func (l *Loader) Load(symbolNames []string) ([]interface{}, error)

func (*Loader) Watch

func (l *Loader) Watch(symbolNames []string, done <-chan bool) (<-chan []interface{}, <-chan error)

Watch watches for changes in the given plugin and emits new symbols on changes

Directories

Path Synopsis
fixtures

Jump to

Keyboard shortcuts

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