plugin

package
v0.0.0-...-b914469 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyInitialized = errors.New("registry has already been initialized")
View Source
var ErrIDInvalidField = errors.New("invalid id: invalid field")
View Source
var ErrIDInvalidFieldName = fmt.Errorf("%w 'Name' (expected: %v)", ErrIDInvalidField, reKeyName)
View Source
var ErrIDInvalidFieldType = fmt.Errorf("%w 'Type' (expected: %v)", ErrIDInvalidField, reKeyType)
View Source
var ErrIDInvalidFieldVersion = fmt.Errorf("%w 'Version' (expected: %v)", ErrIDInvalidField, reKeyVersion)
View Source
var ErrKeyInvalidFormat = errors.New("invalid format: expected <type>/<name>@<version>")
View Source
var ErrManifestNotFound = errors.New("manifest not found")
View Source
var ErrNoPluginsDirPath = errors.New("registry plugin directory path has not been set")
View Source
var ErrNotInitialized = errors.New("registry has not been initialized")

Functions

This section is empty.

Types

type FileSystemRegistry

type FileSystemRegistry struct {
	PluginsDirPath string
	// contains filtered or unexported fields
}

FileSystemRegistry implements plugin.Registry using a local directory of plugins.

func NewFileSystemRegistry

func NewFileSystemRegistry(srcDirPath string) (*FileSystemRegistry, error)

func (*FileSystemRegistry) Initialize

func (r *FileSystemRegistry) Initialize() error

func (*FileSystemRegistry) IsInitialized

func (r *FileSystemRegistry) IsInitialized() bool

func (*FileSystemRegistry) LoadPlugin

func (r *FileSystemRegistry) LoadPlugin(manifest Manifest) (Plugin, error)

LoadPlugin loads a plugin from the registry into the local environment and memory via the passed plugin ID.

func (*FileSystemRegistry) ValidatePlugin

func (r *FileSystemRegistry) ValidatePlugin(pluginID ID) (Manifest, error)

ValidatePlugin validates that the prerequisites of a plugin in the registry are given for the plugin's manifest. Prerequisites may be defined as dependencies, versions, and licensing.

Not to be confused with validating the prerequisites of a plugin in the project during plugin installation.

type ID

type ID struct {
	Name    string `json:"name"`
	Version string `json:"version"`
	Type    Type   `json:"type"`
}

func NewID

func NewID(key string) (ID, error)

func (*ID) FromKey

func (id *ID) FromKey(key string) error

FromKey parses a string plugin identifier key in the format `<type>/<name>@<version>`.

Example key: compile/go-struct@5.3.2

func (ID) String

func (id ID) String() string

String implements the Stringer interface and outputs the plugin identifier as a plugin identifier key in the format `<type>/<name>@<version>` without validation.

func (*ID) ToKey

func (id *ID) ToKey() (string, error)

ToKey validates and outputs a plugin identifier as a plugin identifier key in the format `<type>/<name>@<version>`.

Example key: compile/go-struct@5.3.2

func (*ID) Validate

func (id *ID) Validate() error

Validate checks the ID's fields and values for completeness and having the correct string format.

type InstallValidateable

type InstallValidateable interface {
	OnInstallValidateStart(attempt Installation) error
	OnInstallValidateSuccess(attempt Installation) error
	OnInstallValidateFailure(attempt Installation, failure error)
}

type InstallVerifiable

type InstallVerifiable interface {
	OnInstallVerifyStart(attempt Installation) error
	OnInstallVerifySuccess(attempt Installation) error
	OnInstallVerifyFailure(attempt Installation, failure error)
}

type Installation

type Installation struct {
	UUID      string
	Plugin    Plugin
	StartedAt ti.Time
}

func NewInstallation

func NewInstallation(plugin Plugin) Installation

type Installer

type Installer struct {
	Registry Registry
}

func (*Installer) InstallPlugin

func (i *Installer) InstallPlugin(pluginKey string) error

type Manifest

type Manifest struct {
	ID          ID     `json:"id"`
	Author      string `json:"author"`
	Description string `json:"description"`
}

func (*Manifest) UnmarshalJSON

func (m *Manifest) UnmarshalJSON(data []byte) error

type Plugin

type Plugin struct {
	Manifest Manifest
}

type Registry

type Registry interface {
	// Initialize initializes the plugin once when it is loaded.
	Initialize() error
	// IsInitialized returns whether or not the plugin has been initialized after loading.
	IsInitialized() bool

	// ValidatePlugin validates that the prerequisites of a plugin in the registry are given for the plugin's manifest.
	//
	// Prerequisites may be defined as dependencies, versions, and licensing.
	ValidatePlugin(id ID) (Manifest, error)

	// LoadPlugin loads a plugin from the registry into the local environment and memory via the passed plugin ID.
	LoadPlugin(manifest Manifest) (Plugin, error)
}

type Type

type Type string
const (
	TypeCompile   Type = "compile"
	TypeExecution Type = "execute"
)

Jump to

Keyboard shortcuts

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