plugin

package
v0.0.0-...-522d66a Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterProvider

func RegisterProvider(p Provider)

RegisterProvider adds a new type of provider to the list of providers. The provider that was added last will be used first.

Types

type Identifier

type Identifier struct {
	// Module is the name of the go module that the plugin is in. Generally, this will be formatted as
	// "site.com/author/repo". This will be added to the go.mod file.
	Module string
	// Checksum is a unique string of data that identifies one specific version of a plugin. It is used to determine if
	// the plugin has been updated since the last time the server has been compiled.
	// Any algorithm may be used, as long as it is deterministic and unique for a specific version of a plugin's source
	// code and the provider that was used to get the plugin. For local plugins, it may be the checksum of the entire
	// directory where the plugin's go.mod file is in. For remote git repositories, the commit hash works.
	Checksum string
}

Identifier contains general info about a plugin that uniquely identifies it. It is used to store which plugins were already bundled with the server executable.

func ParseIdentifier

func ParseIdentifier(path string) (Identifier, error)

ParseIdentifier parses Identifier for a local plugin. It accepts the local path of the plugin as a first parameter.

type Module

type Module struct {
	// Module is the name and version of the go module that the plugin is in. Generally, this will be formatted as
	// "site.com/author/repo". This will be added to the go.mod file.
	Module string
	// Version is the version string used in the require directive for the package. It is not use anywhere else, and can
	// be left empty if the plugin does not have a version. An empty version string will be treated as "v0.0.0"
	Version string
	// Replace allows the plugin to optionally add a replace directive to the go.mod file for this plugin. This is
	// usually a path to a local go module.
	Replace string
	// Import returns the package that should be imported for side effects in the server. This is full name of the
	// package (equivalent to how it would be imported) where the plugin is registered to saddle, such as
	// "site.com/author/repo/plugin".
	Import string
}

Module contains data about the plugin that should be bundled and where it can be found. This is used to generate a go.mod file and a main.go file for the server executable.

type Plugin

type Plugin interface {
	// Latest fetches the Identifier for the latest available version that should be downloaded while respecting the
	// configuration of the user. For example, if the user specifies "0.1.7" as a version, this function will return
	// the identifier for that version of the plugin. The result is used to determine whether Plugin.Pull() should be
	// called. This identifier is then assumed to be the identifier of the newly updated plugin.
	Latest() (Identifier, error)
	// Pull will ensure all the necessary files for the plugin are downloaded, if this is needed. Extra checks can also
	// be done here to ensure that the plugin has been downloaded correctly. If an error is returned, the error will be
	// shown and the program will halt. This method is guaranteed to be executed before Plugin.Module().
	Pull() error
	// Module returns info about the go module of the plugin and the package that should be imported. It is used to
	// bundle the plugins.
	Module() Module
}

Plugin represents a source location for a plugin. It is responsible for making sure the plugin is downloaded and in the correct location before the bundling step begins.

func ParseAll

func ParseAll(list []config.PluginInfo) ([]Plugin, error)

ParseAll parses all plugins and tries to identify them. These plugins are then returned. This function does not take care of making sure plugins are downloaded.

type Provider

type Provider = func(info map[string]any) (Plugin, error)

Provider reads the plugin entry in the config data. If this provider type can successfully identify this plugin, it should be returned. If not, nil is returned, which indicates that the function cannot load this plugin. No actual loading should be done here.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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