types

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package types provides type definitions and compatibility helpers for plugins.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FloatPtr

func FloatPtr(f float64) *float64

FloatPtr returns a pointer to the given float64 value.

func RunWithIteration

func RunWithIteration(plugin IterablePlugin, params map[string]interface{}) (interface{}, error)

RunWithIteration executes a plugin with iteration support

Types

type BaseIterablePlugin

type BaseIterablePlugin struct {
	Definition            PluginDefinition
	ExecuteFunc           func(params map[string]interface{}) (interface{}, error)
	IterationFunc         func(params map[string]interface{}, iterationCount int) (interface{}, bool, error)
	SupportsIterationFlag bool
}

BaseIterablePlugin provides a base implementation for plugins that support iteration

func NewIterablePlugin

func NewIterablePlugin(
	definition PluginDefinition,
	executeFunc func(params map[string]interface{}) (interface{}, error),
	iterationFunc func(params map[string]interface{}, iterationCount int) (interface{}, bool, error),
) *BaseIterablePlugin

NewIterablePlugin creates a new plugin instance that supports iteration

func (*BaseIterablePlugin) Execute

func (p *BaseIterablePlugin) Execute(params map[string]interface{}) (interface{}, error)

Execute runs the plugin with the given parameters

func (*BaseIterablePlugin) ExecuteIteration

func (p *BaseIterablePlugin) ExecuteIteration(params map[string]interface{}, iterationCount int) (interface{}, bool, error)

ExecuteIteration runs a single iteration of the plugin

func (*BaseIterablePlugin) GetDefinition

func (p *BaseIterablePlugin) GetDefinition() PluginDefinition

GetDefinition returns the plugin definition

func (*BaseIterablePlugin) SupportsIteration

func (p *BaseIterablePlugin) SupportsIteration() bool

SupportsIteration returns whether the plugin supports iteration

type CompatExecutor

type CompatExecutor struct {
	Definition PluginDefinition
	Executor   PluginExecutor
}

CompatExecutor adapts a legacy PluginExecutor to the newer Plugin interface

func (*CompatExecutor) Execute

func (c *CompatExecutor) Execute(params map[string]interface{}) (interface{}, error)

Execute runs the plugin with the given parameters

func (*CompatExecutor) GetDefinition

func (c *CompatExecutor) GetDefinition() PluginDefinition

GetDefinition returns the plugin definition

type IterablePlugin

type IterablePlugin interface {
	Plugin

	// SupportsIteration returns whether the plugin supports iteration
	SupportsIteration() bool

	// ExecuteIteration runs a single iteration of the plugin with the given parameters
	// and returns whether to continue iterating
	ExecuteIteration(params map[string]interface{}, iterationCount int) (result interface{}, continueIteration bool, err error)
}

IterablePlugin defines the interface for plugins that support iteration

type IterationManager

type IterationManager struct {
	// contains filtered or unexported fields
}

IterationManager handles the execution of iterable plugins

func NewIterationManager

func NewIterationManager(plugin IterablePlugin, config PluginExecutionConfig) *IterationManager

NewIterationManager creates a new iteration manager for a plugin

func (*IterationManager) GetResults

func (im *IterationManager) GetResults() []IterationResult

GetResults returns the results collected so far

func (*IterationManager) IsRunning

func (im *IterationManager) IsRunning() bool

IsRunning returns whether the iteration is currently running

func (*IterationManager) PromptToContinueIteration

func (im *IterationManager) PromptToContinueIteration() bool

PromptToContinueIteration asks whether to continue iterating This can be used by UI to prompt users with "Continue to iterate?"

func (*IterationManager) Start

func (im *IterationManager) Start(params map[string]interface{}) error

Start begins the iteration process

func (*IterationManager) Stop

func (im *IterationManager) Stop()

Stop requests the iteration to stop

func (*IterationManager) WaitForCompletion

func (im *IterationManager) WaitForCompletion()

WaitForCompletion waits for the iteration to complete

type IterationResult

type IterationResult struct {
	IterationCount    int         `json:"iterationCount"`    // Current iteration count
	Result            interface{} `json:"result"`            // Result from this iteration
	ContinueIteration bool        `json:"continueIteration"` // Whether to continue iterating
	Error             string      `json:"error,omitempty"`   // Error message, if any
	Timestamp         time.Time   `json:"timestamp"`         // Time this iteration was completed
}

IterationResult represents the result of a plugin iteration

type LegacyPlugin

type LegacyPlugin struct {
	ID          string      `json:"id"`
	Name        string      `json:"name"`
	Description string      `json:"description"`
	Icon        string      `json:"icon"`
	Parameters  []Parameter `json:"parameters"`
}

LegacyPlugin represents a NetTool plugin structure This is a legacy type, use PluginDefinition or the Plugin interface instead

type LegacyPluginWrapper

type LegacyPluginWrapper struct {
	// contains filtered or unexported fields
}

LegacyPluginWrapper wraps a LegacyPlugin and makes it compatible with the new Plugin interface

func (*LegacyPluginWrapper) Execute

func (w *LegacyPluginWrapper) Execute(params map[string]interface{}) (interface{}, error)

Execute runs the plugin with the given parameters

func (*LegacyPluginWrapper) GetDefinition

func (w *LegacyPluginWrapper) GetDefinition() PluginDefinition

GetDefinition returns the plugin definition converted from the legacy format

type Option

type Option struct {
	Value interface{} `json:"value"`
	Label string      `json:"label"`
}

Option defines an option for a select parameter

type Parameter

type Parameter struct {
	ID          string        `json:"id"`
	Name        string        `json:"name"`
	Description string        `json:"description"`
	Type        ParameterType `json:"type"`
	Required    bool          `json:"required"`
	Default     interface{}   `json:"default,omitempty"`
	Options     []Option      `json:"options,omitempty"` // For select type
	Min         *float64      `json:"min,omitempty"`     // For number/range type
	Max         *float64      `json:"max,omitempty"`     // For number/range type
	Step        *float64      `json:"step,omitempty"`    // For number/range type
}

Parameter defines a plugin parameter This is a legacy type, use PluginParam instead

type ParameterType

type ParameterType string

ParameterType defines the type of a plugin parameter

const (
	// TypeString is the string type identifier.
	TypeString ParameterType = "string"
	// TypeNumber is the number type identifier.
	TypeNumber ParameterType = "number"
	// TypeBoolean is the boolean type identifier.
	TypeBoolean ParameterType = "boolean"
	// TypeSelect is the select type identifier.
	TypeSelect ParameterType = "select"
	// TypeRange is the range type identifier.
	TypeRange ParameterType = "range"
)

type Plugin

type Plugin interface {
	// GetDefinition returns the plugin definition
	GetDefinition() PluginDefinition

	// Execute runs the plugin with the given parameters
	Execute(params map[string]interface{}) (interface{}, error)
}

Plugin defines the interface that all plugins must implement

func ConvertLegacyPluginToNewPlugin

func ConvertLegacyPluginToNewPlugin(lp LegacyPlugin, executor PluginExecutor) Plugin

ConvertLegacyPluginToNewPlugin converts a LegacyPlugin to the Plugin interface

func NewCompatExecutor

func NewCompatExecutor(exec PluginExecutor, def PluginDefinition) Plugin

NewCompatExecutor creates a new compatible executor from a legacy executor

type PluginDefinition

type PluginDefinition struct {
	ID          string        `json:"id"`
	Name        string        `json:"name"`
	Description string        `json:"description"`
	Version     string        `json:"version"`
	Author      string        `json:"author"`
	License     string        `json:"license"`
	Icon        string        `json:"icon"`
	Parameters  []PluginParam `json:"parameters"`
	Requires    []string      `json:"requires,omitempty"` // System dependencies like iperf3
	Repository  string        `json:"repository,omitempty"`
}

PluginDefinition defines the structure for plugin metadata and configuration

func CompatPlugin

func CompatPlugin(p *LegacyPlugin) PluginDefinition

CompatPlugin converts a legacy LegacyPlugin structure to a PluginDefinition

type PluginExecutionConfig

type PluginExecutionConfig struct {
	Iterate         bool `json:"iterate"`         // Whether to iterate execution
	MaxIterations   int  `json:"maxIterations"`   // Maximum number of iterations (0 = unlimited)
	IterationDelay  int  `json:"iterationDelay"`  // Delay between iterations in milliseconds
	ContinueOnError bool `json:"continueOnError"` // Whether to continue iterating after an error
}

PluginExecutionConfig defines configuration for plugin execution

func ExtractIterationConfig

func ExtractIterationConfig(params map[string]interface{}) PluginExecutionConfig

ExtractIterationConfig extracts iteration configuration from parameters

type PluginExecutor

type PluginExecutor interface {
	Execute(params map[string]interface{}) (interface{}, error)
}

PluginExecutor is the interface that must be implemented by all plugins This is a legacy interface, use the Plugin interface instead

type PluginParam

type PluginParam struct {
	ID          string        `json:"id"`
	Name        string        `json:"name"`
	Description string        `json:"description"`
	Type        ParameterType `json:"type"`
	Required    bool          `json:"required"`
	Default     interface{}   `json:"default,omitempty"`
	Options     []Option      `json:"options,omitempty"`    // For select type
	Min         *float64      `json:"min,omitempty"`        // For number/range type
	Max         *float64      `json:"max,omitempty"`        // For number/range type
	Step        *float64      `json:"step,omitempty"`       // For number/range type
	CanIterate  bool          `json:"canIterate,omitempty"` // Whether this parameter supports iteration
}

PluginParam defines a parameter for a plugin

func CreateIterationParams

func CreateIterationParams() PluginParam

CreateIterationParams creates a standard iteration parameter for plugins

Jump to

Keyboard shortcuts

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