-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.go
More file actions
76 lines (57 loc) · 2.69 KB
/
plugin.go
File metadata and controls
76 lines (57 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// plugin.go: Core plugin interfaces and types
//
// Copyright (c) 2025 AGILira - A. Giordano
// Series: an AGILira library
// SPDX-License-Identifier: MPL-2.0
package goplugins
import (
"context"
)
// Plugin represents a generic plugin that can process requests of type Req and return responses of type Resp
// This interface is designed to be transport-agnostic and production-ready
type Plugin[Req, Resp any] interface {
// Info returns metadata about the plugin
Info() PluginInfo
// Execute processes a request and returns a response
// Context should be honored for timeouts and cancellation
Execute(ctx context.Context, execCtx ExecutionContext, request Req) (Resp, error)
// Health performs a health check and returns detailed status
Health(ctx context.Context) HealthStatus
// Close gracefully shuts down the plugin and cleans up resources
// Should be idempotent (safe to call multiple times)
Close() error
}
// PluginManager manages a collection of plugins and provides circuit breaking
// and health monitoring
type PluginManager[Req, Resp any] interface {
// Register adds a plugin to the manager
Register(plugin Plugin[Req, Resp]) error
// Unregister removes a plugin from the manager
Unregister(name string) error
// Execute routes a request to the appropriate plugin
// Includes automatic retries, circuit breaking, and fallback handling
Execute(ctx context.Context, pluginName string, request Req) (Resp, error)
// ExecuteWithOptions executes with custom execution context
ExecuteWithOptions(ctx context.Context, pluginName string, execCtx ExecutionContext, request Req) (Resp, error)
// GetPlugin returns a specific plugin by name
GetPlugin(name string) (Plugin[Req, Resp], error)
// ListPlugins returns all registered plugin names and their health status
ListPlugins() map[string]HealthStatus
// LoadFromConfig loads plugins from a configuration file or object
LoadFromConfig(config ManagerConfig) error
// ReloadConfig hot-reloads configuration without stopping the manager
ReloadConfig(config ManagerConfig) error
// Health returns the overall health of all plugins
Health() map[string]HealthStatus
// Shutdown gracefully shuts down all plugins and cleans up resources
Shutdown(ctx context.Context) error
}
// PluginFactory creates new plugin instances from configuration
type PluginFactory[Req, Resp any] interface {
// CreatePlugin creates a new plugin instance from the given configuration
CreatePlugin(config PluginConfig) (Plugin[Req, Resp], error)
// SupportedTransports returns the list of supported transport protocols
SupportedTransports() []string
// ValidateConfig validates a plugin configuration without creating the plugin
ValidateConfig(config PluginConfig) error
}