agent

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRestartRequested = errors.New("agent restart requested")

ErrRestartRequested is returned by a command handler to signal that the agent should restart itself after sending a success result to the panel.

Functions

func BoolArg

func BoolArg(args map[string]any, key string) bool

BoolArg extracts a bool from args, returning false when absent.

func StringArg

func StringArg(args map[string]any, key string) string

StringArg extracts a string from args, returning "" when absent.

Types

type Client

type Client struct {
	URL               string
	Token             string
	Name              string
	Version           string
	HeartbeatInterval time.Duration
	ReconnectDelay    time.Duration
	Executor          *Executor
	AllowedScopes     []string // nil = all scopes; sent in hello/heartbeat so the panel knows
	// contains filtered or unexported fields
}

Client connects to a zeus web panel, authenticates with a token, and dispatches incoming commands to the Executor. It reconnects automatically on disconnect.

func (*Client) Run

func (c *Client) Run(ctx context.Context) error

Run connects and blocks until ctx is cancelled.

type Executor

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

Executor is a registry of command handlers. It is safe for concurrent use.

func NewExecutor

func NewExecutor() *Executor

func (*Executor) Dispatch

func (e *Executor) Dispatch(ctx context.Context, cmd string, args map[string]any, w io.Writer) error

Dispatch looks up the handler for cmd and runs it. Returns an error if the command is unknown, not in the allowed set, or the handler fails.

func (*Executor) Register

func (e *Executor) Register(cmd string, h HandlerFunc)

Register associates a command name with a handler. Calling Register twice for the same name replaces the previous handler.

func (*Executor) SetAllowed

func (e *Executor) SetAllowed(allowed map[string]bool)

SetAllowed restricts dispatch to the given command set. Pass nil to remove restrictions (allow all).

type HandlerFunc

type HandlerFunc func(ctx context.Context, args map[string]any, w io.Writer) error

HandlerFunc is the signature every command handler must implement. args mirrors the Command.Args map from the protocol envelope. w receives all output lines that will be streamed back to the server.

type StatusFunc

type StatusFunc func() []protocol.ProfileStatus

StatusFunc returns the current running state of all profiles. Client calls it for each heartbeat.

Jump to

Keyboard shortcuts

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