Documentation
¶
Overview ¶
Package plugin provides external plugin loading capabilities for GoSPA. This enables loading plugins from external sources like GitHub repositories.
Package plugin provides the plugin system for GoSPA.
Index ¶
- Variables
- func Disable(name string) error
- func Enable(name string) error
- func InstallPlugin(ref string) error
- func ParsePluginRef(ref string) (owner, repo, version string, err error)
- func Register(p Plugin) error
- func ResolveDependencies() error
- func RunCommand(name string, args []string) (bool, error)
- func TriggerHook(hook Hook, ctx map[string]interface{}) error
- func TriggerHookForPlugin(name string, hook Hook, ctx map[string]interface{}) error
- func UninstallPlugin(name string) error
- func Unregister(name string)
- func ValidatePluginRef(ref string) error
- type CLIPlugin
- type Command
- type Config
- type Dependency
- type DependencyType
- type ExternalPluginLoader
- type FieldSchema
- type Flag
- type Hook
- type Info
- type Metadata
- type Plugin
- type RegistryEntry
- type RuntimePlugin
- type State
Constants ¶
This section is empty.
Variables ¶
var PluginCacheDir = getPluginCacheDir()
PluginCacheDir is the directory where external plugins are cached.
Functions ¶
func InstallPlugin ¶ added in v0.1.29
InstallPlugin installs a plugin from a remote source.
func ParsePluginRef ¶ added in v0.1.29
ParsePluginRef parses a plugin reference string into owner, repo, and version. Supports formats:
- github.com/owner/repo
- github.com/owner/repo@version
- owner/repo (shorthand)
- owner/repo@version (shorthand)
func Register ¶
Register registers a plugin with GoSPA. This function is thread-safe and can be called from multiple goroutines. Returns an error if a plugin with the same name is already registered.
func ResolveDependencies ¶ added in v0.1.29
func ResolveDependencies() error
ResolveDependencies installs all plugin dependencies.
func RunCommand ¶
RunCommand executes a custom command from a plugin.
func TriggerHook ¶
TriggerHook triggers a lifecycle hook for all registered CLI plugins concurrently.
func TriggerHookForPlugin ¶ added in v0.1.29
TriggerHookForPlugin triggers a lifecycle hook for a specific plugin by name.
func UninstallPlugin ¶ added in v0.1.29
UninstallPlugin removes a cached plugin.
func Unregister ¶ added in v0.1.29
func Unregister(name string)
Unregister removes a plugin from the registry.
func ValidatePluginRef ¶ added in v0.1.29
ValidatePluginRef validates a plugin reference string.
Types ¶
type CLIPlugin ¶
type CLIPlugin interface {
Plugin
// OnHook is called when a lifecycle hook is triggered.
OnHook(hook Hook, ctx map[string]interface{}) error
// Commands returns custom CLI commands provided by the plugin.
Commands() []Command
}
CLIPlugin extends Plugin with CLI-specific functionality.
func GetCLIPlugins ¶
func GetCLIPlugins() []CLIPlugin
GetCLIPlugins returns all registered CLI plugins. This function is thread-safe.
type Command ¶
type Command struct {
Name string
Alias string
Description string
Action func(args []string) error
// Flags defines command-line flags for this command.
Flags []Flag
}
Command represents a custom CLI command.
type Config ¶ added in v0.1.29
type Config struct {
// Schema describes the configuration fields.
Schema map[string]FieldSchema `json:"schema" yaml:"schema"`
// Defaults provides default values.
Defaults map[string]interface{} `json:"defaults" yaml:"defaults"`
}
Config defines plugin configuration structure.
type Dependency ¶
type Dependency struct {
// Type is the dependency type (go or bun).
Type DependencyType
// Name is the package name (e.g., "golang.org/x/oauth2" or "valibot").
Name string
// Version is the version constraint (e.g., "latest", "v1.2.3").
Version string
}
Dependency represents a plugin dependency.
func GetAllDependencies ¶ added in v0.1.29
func GetAllDependencies() []Dependency
GetAllDependencies returns all dependencies from enabled plugins.
type DependencyType ¶
type DependencyType string
DependencyType represents the type of dependency (Go or Bun/JS).
const ( // DepGo is a Go module dependency. DepGo DependencyType = "go" // DepBun is a Bun/JavaScript package dependency. DepBun DependencyType = "bun" )
type ExternalPluginLoader ¶ added in v0.1.29
type ExternalPluginLoader struct {
// contains filtered or unexported fields
}
ExternalPluginLoader handles loading plugins from external sources.
func NewExternalPluginLoader ¶ added in v0.1.29
func NewExternalPluginLoader() *ExternalPluginLoader
NewExternalPluginLoader creates a new loader with the default cache directory.
func NewExternalPluginLoaderWithCache ¶ added in v0.1.29
func NewExternalPluginLoaderWithCache(cacheDir string) *ExternalPluginLoader
NewExternalPluginLoaderWithCache creates a new loader with a custom cache directory.
func (*ExternalPluginLoader) AllowMutableRefs ¶ added in v0.1.31
func (l *ExternalPluginLoader) AllowMutableRefs(allow bool) *ExternalPluginLoader
AllowMutableRefs enables or disables mutable refs such as "latest". Mutable refs are disabled by default to keep plugin installs reproducible.
func (*ExternalPluginLoader) ExpectResolvedRef ¶ added in v0.1.31
func (l *ExternalPluginLoader) ExpectResolvedRef(ref string) *ExternalPluginLoader
ExpectResolvedRef pins plugin loading to an exact commit SHA (40 hex chars). When set, cached and newly downloaded plugins must match this commit.
func (*ExternalPluginLoader) LoadFromGitHub ¶ added in v0.1.29
func (l *ExternalPluginLoader) LoadFromGitHub(ref string) (Plugin, error)
LoadFromGitHub downloads and loads a plugin from a GitHub repository. The ref can be in the following formats:
- github.com/owner/repo
- github.com/owner/repo@version
- owner/repo
- owner/repo@version
type FieldSchema ¶ added in v0.1.29
type FieldSchema struct {
Type string `json:"type" yaml:"type"` // "string", "bool", "number", "array"
Description string `json:"description" yaml:"description"` // Human-readable description
Required bool `json:"required" yaml:"required"` // Is this field required?
Default interface{} `json:"default" yaml:"default"` // Default value
}
FieldSchema describes a single configuration field.
type Hook ¶
type Hook string
Hook represents a lifecycle event in GoSPA.
const ( // BeforeGenerate is triggered before code generation starts. BeforeGenerate Hook = "before:generate" // AfterGenerate is triggered after code generation completes. AfterGenerate Hook = "after:generate" // BeforeDev is triggered before the development server starts. BeforeDev Hook = "before:dev" // AfterDev is triggered after the development server stops. AfterDev Hook = "after:dev" // BeforeBuild is triggered before the production build starts. BeforeBuild Hook = "before:build" // AfterBuild is triggered after the production build completes. AfterBuild Hook = "after:build" // BeforeServe is triggered before the HTTP server starts. BeforeServe Hook = "before:serve" // AfterServe is triggered after the HTTP server starts. AfterServe Hook = "after:serve" // BeforePrune is triggered before state pruning. BeforePrune Hook = "before:prune" // AfterPrune is triggered after state pruning. AfterPrune Hook = "after:prune" // OnError is triggered when an error occurs. OnError Hook = "on:error" )
type Info ¶ added in v0.1.29
type Info struct {
Name string // Unique identifier
Version string // Semantic version
Description string // Human-readable description
Author string // Plugin author
State State // Current state
}
Info provides metadata about a plugin.
func GetAllPluginInfo ¶ added in v0.1.29
func GetAllPluginInfo() []Info
GetAllPluginInfo returns metadata for all registered plugins.
func GetPluginInfo ¶ added in v0.1.29
GetPluginInfo returns metadata for a specific plugin.
type Metadata ¶ added in v0.1.29
type Metadata struct {
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description,omitempty"`
Author string `json:"author,omitempty"`
Source string `json:"source"`
ResolvedRef string `json:"resolvedRef,omitempty"`
}
Metadata holds metadata about an external plugin.
type Plugin ¶
type Plugin interface {
Name() string
Init() error
// Dependencies returns the list of dependencies required by this plugin.
Dependencies() []Dependency
}
Plugin is the base interface for all GoSPA extensions.
func GetPlugin ¶ added in v0.1.29
GetPlugin returns a registered plugin by name. Returns nil if the plugin is not found.
func GetPlugins ¶
func GetPlugins() []Plugin
GetPlugins returns all registered plugins. This function is thread-safe and returns a copy of the registry.
type RegistryEntry ¶ added in v0.1.29
type RegistryEntry struct {
Name string `json:"name"`
Description string `json:"description"`
URL string `json:"url"`
Version string `json:"version"`
Installed bool `json:"installed"`
}
RegistryEntry represents a plugin in the registry.
func DiscoverPlugins ¶ added in v0.1.29
func DiscoverPlugins() ([]RegistryEntry, error)
DiscoverPlugins queries a plugin registry for available plugins. This is a placeholder that would connect to an actual registry service.
func ListInstalledPlugins ¶ added in v0.1.29
func ListInstalledPlugins() ([]RegistryEntry, error)
ListInstalledPlugins returns all installed external plugins.
func SearchPlugins ¶ added in v0.1.29
func SearchPlugins(query string) ([]RegistryEntry, error)
SearchPlugins searches the registry for plugins matching a query.
type RuntimePlugin ¶ added in v0.1.29
type RuntimePlugin interface {
Plugin
// Config returns the plugin configuration schema.
Config() Config
// Middlewares returns Fiber handlers to inject into the app.
Middlewares() []interface{} // []fiber.Handler
// TemplateFuncs returns template functions to expose to templ components.
TemplateFuncs() map[string]interface{}
}
RuntimePlugin extends Plugin with runtime integration capabilities.
func GetRuntimePlugins ¶ added in v0.1.29
func GetRuntimePlugins() []RuntimePlugin
GetRuntimePlugins returns all registered runtime plugins. This function is thread-safe.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package auth provides authentication for GoSPA projects.
|
Package auth provides authentication for GoSPA projects. |
|
Package image provides image optimization for GoSPA projects.
|
Package image provides image optimization for GoSPA projects. |
|
Package postcss provides a PostCSS plugin for GoSPA with Tailwind CSS v4 support.
|
Package postcss provides a PostCSS plugin for GoSPA with Tailwind CSS v4 support. |
|
Package qrcode provides QR code generation for GoSPA applications.
|
Package qrcode provides QR code generation for GoSPA applications. |
|
Package seo provides SEO optimization for GoSPA projects.
|
Package seo provides SEO optimization for GoSPA projects. |
|
Package tailwind provides a Tailwind CSS v4 plugin for GoSPA.
|
Package tailwind provides a Tailwind CSS v4 plugin for GoSPA. |
|
Package validation provides form validation for GoSPA projects.
|
Package validation provides form validation for GoSPA projects. |